Sha256: cc179a7485e0435c95409edba67ca5126d6af756e4da3a9d6066b3242bb1ef96

Contents?: true

Size: 886 Bytes

Versions: 11

Compression:

Stored size: 886 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

11 entries across 11 versions & 1 rubygems

Version Path
unitwise-0.6.0 lib/unitwise/expression/matcher.rb
unitwise-0.5.1 lib/unitwise/expression/matcher.rb
unitwise-0.5.0 lib/unitwise/expression/matcher.rb
unitwise-0.4.0 lib/unitwise/expression/matcher.rb
unitwise-0.3.2 lib/unitwise/expression/matcher.rb
unitwise-0.3.1 lib/unitwise/expression/matcher.rb
unitwise-0.3.0 lib/unitwise/expression/matcher.rb
unitwise-0.2.2 lib/unitwise/expression/matcher.rb
unitwise-0.2.1 lib/unitwise/expression/matcher.rb
unitwise-0.2.0 lib/unitwise/expression/matcher.rb
unitwise-0.1.0 lib/unitwise/expression/matcher.rb