module SillyId
Constants
- VERSION
Public Class Methods
haiku(token_range = 9999, delimiter = '-')
click to toggle source
# File lib/silly-id.rb, line 9 def haiku(token_range = 9999, delimiter = '-') build_haiku(token_range, delimiter) end
Private Class Methods
adjectives()
click to toggle source
# File lib/silly-id.rb, line 49 def adjectives File.read(File.expand_path("../silly-id/words/#{locale}_adjectives.txt", __FILE__)).split("\n") end
build_haiku(token_range, delimiter)
click to toggle source
# File lib/silly-id.rb, line 15 def build_haiku(token_range, delimiter) sections = [ adjectives[random_seed % adjectives.length], nouns[random_seed % nouns.length], token(token_range) ] sections.compact.join(delimiter) end
locale()
click to toggle source
# File lib/silly-id.rb, line 45 def locale locale_supported?(I18n.locale) ? I18n.locale : :en end
locale_supported?(locale)
click to toggle source
# File lib/silly-id.rb, line 41 def locale_supported?(locale) supported_locales.include?(locale) end
nouns()
click to toggle source
# File lib/silly-id.rb, line 53 def nouns File.read(File.expand_path("../silly-id/words/#{locale}_nouns.txt", __FILE__)).split("\n") end
random_seed()
click to toggle source
# File lib/silly-id.rb, line 25 def random_seed SecureRandom.random_number(4096) end
supported_locales()
click to toggle source
# File lib/silly-id.rb, line 33 def supported_locales @supported_locales ||= begin Dir.glob(File.expand_path("../silly-id/words/*", __FILE__)).map do |path| File.basename(path, ".txt").split('_').first.to_sym end.uniq.sort end end
token(range)
click to toggle source
# File lib/silly-id.rb, line 29 def token(range) SecureRandom.random_number(range) if range.positive? end