Class: UState::Query::Approximately

Inherits:
Object
  • Object
show all
Defined in:
lib/ustate/query/approximately.rb

Instance Method Summary collapse

Constructor Details

#initialize(field, value) ⇒ Approximately

Returns a new instance of Approximately.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ustate/query/approximately.rb', line 3

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

Instance Method Details

#===(state) ⇒ Object



20
21
22
# File 'lib/ustate/query/approximately.rb', line 20

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