Sha256: da1f895ec71c4efa9967d8399db73c65efa30b1eb247de60611341511d494de9

Contents?: true

Size: 531 Bytes

Versions: 1

Compression:

Stored size: 531 Bytes

Contents

class UState::Query
  class Approximately < Node
    def initialize(field, value)
      @field = field
      @value = case value
        when String
          r = value.chars.inject('') do |r, c|
            if c == '%'
              r << '.*'
            else
              r << Regexp.escape(c)
            end
          end
          /^#{r}$/
        else
          value
        end
    end

    def ===(state)
      @value === state.send(@field) 
    end

    def inspect
      inspect_helper @field, @value
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ustate-client-0.0.7 lib/ustate/query/approximately.rb