Tekido is a module that generates various random value.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install tekido
Tekido has below methods. (All methods are dependent on
It returns random boolean.
# true: 50%, false: 50% Tekido.yes? # true: 80%, false: 20% Tekido.yes?(80)
It retuens random percentage (0..100). It behaves the same as
It returns random percentage. Can select return value type.
# returns integer (Tekido.percent behaves it, too) Tekido.percent_as(:integer) # returns float Tekido.percent_as(:float) # returns integer that is multiple of 5 (ex. 10, 35) Tekido.percent_as(:mo5) # returns integer that is multiple of 10 (ex. 10, 70) Tekido.percent_as(:deca) Tekido.percent_as(:mo10)
It always returns random value as integer.
# returns integer (0 <= value <= 1073741823) Tekido.integer # returns integer that not over argument Tekido.integer(9999) # returns integer that is included in argument Tekido.integer(1..1234)
It always returns random value as float. The different with
rand is return value type only.
# returns float (0 <= value < 1) Tekido.float # returns float that not over argument Tekido.float(777.77) # returns float that is included in argument Tekido.float(1..1234) Tekido.float(1.1..1234.5)
It returns Array instance that is filled by given sample values and ratio.
# returns Array instance that contains 'one': 25%, 'two': 25%, 'three': 25%, 'four': 25% Tekido.list(10000, %w(one two three four)) # returns Array instance that contains 'one': 11.1%, 'two': 22.2%, 'three': 33.3%, 'four': 33.4% Tekido.list(10000, 'one' => 11.1, 'two' => 22.2, 'three' => 33.3, 'four' => 33.4) # returns Array instance that contains 'one': 10%, 'two': 20%, 'three': 30%, nil: 40% (rests) Tekido.list(10000, 'one' => 10, 'two' => 20, 'three' => 30)
It returns random Date instance.
# returns Date (0001-01-01 <= value <= 9999-12-31) Tekido.date # returns Date (2010-01-01 <= value <= 2010-12-31) Tekido.date(2010) # returns Date (1999-01-01 <= value <= 2007-12-31) Tekido.date(1999..2007) # returns Date (1999-02-21 <= value <= 2003-10-07) Tekido.date(Date.new(1999, 2, 21)..Date.new(2003, 10, 7))
It returns random birthday as Date instance.
# returns Date as birthday satisfying that current age is more than 0 and less than 100 Tekido.birthday # returns Date as birthday satisfying that current age is given argument Tekido.birthday(28) # returns Date as birthday satisfying that current age is within given argument Tekido.birthday(21..25)
It returns random String instance.
# returns String instance that is costructed by upper characters, lower characters and numeric characters, and size is within 1..255. Tekido.string # returns String instance that is costructed by lower characters and numeric characters, and size is 10. # components option accepts :upper or :lower or :number or combination of these. Tekido.string(size: 10, components: [:upper, :number]) # returns String instance that is costructed by given characters (ex. x39yyz177x) , and size is within 8..16. # chars option overrides components option Tekido.string(size: 8..16, chars: %w(1 3 5 7 9 x y z))
It returns random email address.
# returns email address that has example domain. (ex. email@example.com) Tekido.email # returns email address that has given domain. (ex. firstname.lastname@example.org) Tekido.email('foobar.com') # returns email address that has same domain as given email address. (ex. email@example.com) Tekido.email("firstname.lastname@example.org") # .email accepts multiple domains or base email addresses. Tekido.email('email@example.com', 'bar.com', '@baz.com')
Supported ruby versions
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request