Class: Unitwise::Expression::Matcher
- Inherits:
-
Object
- Object
- Unitwise::Expression::Matcher
- Defined in:
- lib/unitwise/expression/matcher.rb
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.
20 21 22 23 |
# File 'lib/unitwise/expression/matcher.rb', line 20 def initialize(collection, mode=:primary_code) @collection = collection @mode = mode end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
18 19 20 |
# File 'lib/unitwise/expression/matcher.rb', line 18 def collection @collection end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
18 19 20 |
# File 'lib/unitwise/expression/matcher.rb', line 18 def mode @mode end |
Class Method Details
.atom(mode) ⇒ Object
5 6 7 |
# File 'lib/unitwise/expression/matcher.rb', line 5 def atom(mode) new(Atom.all, mode).alternative end |
Instance Method Details
#alternative ⇒ Object
35 36 37 |
# File 'lib/unitwise/expression/matcher.rb', line 35 def alternative @alternative ||= Parslet::Atoms::Alternative.new(*matchers) end |
#matchers ⇒ Object
31 32 33 |
# File 'lib/unitwise/expression/matcher.rb', line 31 def matchers @matchers ||= strings.map {|s| Parslet::Atoms::Str.new(s) } end |
#strings ⇒ Object
25 26 27 28 29 |
# File 'lib/unitwise/expression/matcher.rb', line 25 def strings @stings ||= collection.map(&mode).flatten.compact.sort do |x,y| y.length <=> x.length end end |