Class: PatternExpander
- Inherits:
-
Object
- Object
- PatternExpander
- Defined in:
- lib/pattern_expander.rb,
lib/pattern_expander/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Instance Attribute Summary collapse
-
#combination_index ⇒ Object
readonly
Returns the value of attribute combination_index.
Instance Method Summary collapse
- #[](index_or_range) ⇒ Object
-
#initialize(pattern, substitutes: nil, parser_class: PatternParser) ⇒ PatternExpander
constructor
A new instance of PatternExpander.
- #sample(quantity = 1) ⇒ Object
Constructor Details
#initialize(pattern, substitutes: nil, parser_class: PatternParser) ⇒ PatternExpander
Returns a new instance of PatternExpander.
7 8 9 10 11 12 13 14 15 |
# File 'lib/pattern_expander.rb', line 7 def initialize(pattern, substitutes: nil, parser_class: PatternParser) unless substitutes.nil? parser = parser_class.new(substitutes: substitutes) else parser = parser_class.new end @combination_index = CombinationIndex.new(parser.parse(pattern)) end |
Instance Attribute Details
#combination_index ⇒ Object (readonly)
Returns the value of attribute combination_index.
5 6 7 |
# File 'lib/pattern_expander.rb', line 5 def combination_index @combination_index end |
Instance Method Details
#[](index_or_range) ⇒ Object
17 18 19 |
# File 'lib/pattern_expander.rb', line 17 def [](index_or_range) combination_index[index_or_range] end |
#sample(quantity = 1) ⇒ Object
21 22 23 |
# File 'lib/pattern_expander.rb', line 21 def sample(quantity=1) combination_index.sample(quantity) end |