Class: UState::Query::Approximately

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

Instance Method Summary collapse

Methods included from Binarity

#==, #a, #b, #children, #children=, #inspect, #mass, #to_s

Methods inherited from Node

#indent, #inspect, #inspect_helper, #mass

Constructor Details

#initialize(field, value) ⇒ Approximately

Returns a new instance of Approximately.



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

def initialize(field, value)
  @a = field
  @b = 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



22
23
24
# File 'lib/ustate/query/approximately.rb', line 22

def ===(state)
  @b === state.send(@a) 
end