Class: Wildling::Generator
- Inherits:
-
Object
- Object
- Wildling::Generator
- Defined in:
- lib/wildling/generator.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #count ⇒ Object
- #get(index) ⇒ Object
-
#initialize(input_pattern, dictionaries) ⇒ Generator
constructor
A new instance of Generator.
- #tokens ⇒ Object
Constructor Details
#initialize(input_pattern, dictionaries) ⇒ Generator
Returns a new instance of Generator.
9 10 11 12 13 14 |
# File 'lib/wildling/generator.rb', line 9 def initialize(input_pattern, dictionaries) @source = input_pattern @tokens = ::Wildling.parse_pattern(input_pattern, dictionaries) @count = 1 @tokens.each { |token| @count *= token.count } end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
7 8 9 |
# File 'lib/wildling/generator.rb', line 7 def source @source end |
Instance Method Details
#count ⇒ Object
16 17 18 |
# File 'lib/wildling/generator.rb', line 16 def count @count end |
#get(index) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/wildling/generator.rb', line 24 def get(index) return "" if index > @count - 1 || index < 0 string_array = [] index_with_offset = index @tokens.each do |token| string_array << token.get(index_with_offset % token.count) index_with_offset /= token.count end string_array.join end |
#tokens ⇒ Object
20 21 22 |
# File 'lib/wildling/generator.rb', line 20 def tokens @tokens end |