Sha256: 6ea7e8888f716b8a5353ab692c070d0e1eb4362eed8c097c076a131d5f8969b0

Contents?: true

Size: 887 Bytes

Versions: 6

Compression:

Stored size: 887 Bytes

Contents

module Unitwise
  module Expression
    class Matcher
      class << self
        def atom(method)
          new(Atom.all, method).alternative
        end

        def metric_atom(method)
          new(Atom.all.select(&:metric?), method).alternative
        end

        def prefix(method)
          new(Prefix.all, method).alternative
        end
      end

      attr_reader :collection, :method

      def initialize(collection, method=:primary_code)
        @collection = collection
        @method = method
      end

      def strings
        @stings ||= collection.map(&method).flatten.compact.sort do |x,y|
          y.length <=> x.length
        end
      end

      def matchers
        @matchers ||= strings.map {|s| Parslet::Atoms::Str.new(s) }
      end

      def alternative
        @alternative ||= Parslet::Atoms::Alternative.new(*matchers)
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
unitwise-0.8.1 lib/unitwise/expression/matcher.rb
unitwise-0.8.0 lib/unitwise/expression/matcher.rb
unitwise-0.7.1 lib/unitwise/expression/matcher.rb
unitwise-0.7.0 lib/unitwise/expression/matcher.rb
unitwise-0.6.2 lib/unitwise/expression/matcher.rb
unitwise-0.6.1 lib/unitwise/expression/matcher.rb