class Unitwise::Expression::Matcher
Matcher
is responsible for building up Parslet alternatives of atoms and prefixes to be used by Unitwise::Expression::Parser
.
Attributes
collection[R]
mode[R]
Public Class Methods
atom(mode)
click to toggle source
# File lib/unitwise/expression/matcher.rb, line 7 def atom(mode) new(Atom.all, mode).alternative end
metric_atom(mode)
click to toggle source
# File lib/unitwise/expression/matcher.rb, line 11 def metric_atom(mode) new(Atom.all.select(&:metric?), mode).alternative end
new(collection, mode = :primary_code)
click to toggle source
# File lib/unitwise/expression/matcher.rb, line 22 def initialize(collection, mode = :primary_code) @collection = collection @mode = mode end
prefix(mode)
click to toggle source
# File lib/unitwise/expression/matcher.rb, line 15 def prefix(mode) new(Prefix.all, mode).alternative end
Public Instance Methods
alternative()
click to toggle source
# File lib/unitwise/expression/matcher.rb, line 37 def alternative Parslet::Atoms::Alternative.new(*matchers) end
matchers()
click to toggle source
# File lib/unitwise/expression/matcher.rb, line 33 def matchers strings.map { |s| Parslet::Atoms::Str.new(s) } end
strings()
click to toggle source
# 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