Class: Unitwise::Expression::Matcher
- Inherits:
-
Object
- Object
- Unitwise::Expression::Matcher
- Defined in:
- lib/unitwise/expression/matcher.rb
Overview
Matcher is responsible for building up Parslet alternatives of atoms and prefixes to be used by Unitwise::Expression::Parser.
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
Class Method Summary collapse
Instance Method Summary collapse
- #alternative ⇒ Object
-
#initialize(collection, mode = :primary_code) ⇒ Matcher
constructor
A new instance of Matcher.
- #matchers ⇒ Object
- #strings ⇒ Object
Constructor Details
#initialize(collection, mode = :primary_code) ⇒ Matcher
Returns a new instance of Matcher.
22 23 24 25 |
# File 'lib/unitwise/expression/matcher.rb', line 22 def initialize(collection, mode = :primary_code) @collection = collection @mode = mode end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
20 21 22 |
# File 'lib/unitwise/expression/matcher.rb', line 20 def collection @collection end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
20 21 22 |
# File 'lib/unitwise/expression/matcher.rb', line 20 def mode @mode end |
Class Method Details
.atom(mode) ⇒ Object
7 8 9 |
# File 'lib/unitwise/expression/matcher.rb', line 7 def atom(mode) new(Atom.all, mode).alternative end |
Instance Method Details
#alternative ⇒ Object
37 38 39 |
# File 'lib/unitwise/expression/matcher.rb', line 37 def alternative Parslet::Atoms::Alternative.new(*matchers) end |
#matchers ⇒ Object
33 34 35 |
# File 'lib/unitwise/expression/matcher.rb', line 33 def matchers strings.map { |s| Parslet::Atoms::Str.new(s) } end |
#strings ⇒ Object
27 28 29 30 31 |
# File 'lib/unitwise/expression/matcher.rb', line 27 def strings collection.map(&mode).flatten.compact.sort do |x, y| y.length <=> x.length end end |