Sha256: 0840bf3f26ff2c4ad2017d75243e576bf5701a06f763311ad6fe0523c1cb6f69

Contents?: true

Size: 463 Bytes

Versions: 4

Compression:

Stored size: 463 Bytes

Contents

class UState::Query
  class Approximately
    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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ustate-client-0.0.6 lib/ustate/query/approximately.rb
ustate-client-0.0.5 lib/ustate/query/approximately.rb
ustate-client-0.0.4 lib/ustate/query/approximately.rb
ustate-client-0.0.3 lib/ustate/query/approximately.rb