class EnterRockstar::Generator::Poetic
poetic number generator
Constants
- STRATEGIES
Attributes
amount[R]
strategy[R]
tokens[R]
Public Class Methods
new(data_file:, amount: 5, strategy: 'random')
click to toggle source
# File lib/enter_rockstar/generator/poetic.rb, line 13 def initialize(data_file:, amount: 5, strategy: 'random') @tokens = JSON.parse EnterRockstar::Utils.load_json(data_file) @amount = Integer(amount) rescue 5 @strategy = STRATEGIES[strategy] || '_random' end
Public Instance Methods
number(num)
click to toggle source
# File lib/enter_rockstar/generator/poetic.rb, line 19 def number(num) # split the number into parts array = num.to_s.split(/\B|\b/) all_results = [] @amount.times do result = send(@strategy, array) all_results.push result.join(' ') end all_results end
Private Instance Methods
_random(array)
click to toggle source
# File lib/enter_rockstar/generator/poetic.rb, line 34 def _random(array) result = [] array.each do |digit| if digit == '.' result << '.' next end # digits less than 4 should use longer words digit = digit.to_i < 4 ? (digit.to_i + 10).to_s : digit result << @tokens[digit].sample end result end