Class: Icemaker::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/icemaker/filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, value_to_test, test) ⇒ Filter

Returns a new instance of Filter.



90
91
92
93
94
95
# File 'lib/icemaker/filter.rb', line 90

def initialize(tag, value_to_test, test)
  @tag = tag
  @value_to_test = value_to_test
  @test = test
  @tag_value = ''
end

Instance Attribute Details

#tag_value=(value) ⇒ Object (writeonly)

Sets the attribute tag_value

Parameters:

  • value

    the value to set the attribute tag_value to.



5
6
7
# File 'lib/icemaker/filter.rb', line 5

def tag_value=(value)
  @tag_value = value
end

Instance Method Details

#containsObject



48
49
50
# File 'lib/icemaker/filter.rb', line 48

def contains
  has
end

#eqObject



66
67
68
# File 'lib/icemaker/filter.rb', line 66

def eq
  is
end

#gtObject



82
83
84
# File 'lib/icemaker/filter.rb', line 82

def gt
  @tag_value > @value_to_test
end

#gteObject



74
75
76
# File 'lib/icemaker/filter.rb', line 74

def gte
  @tag_value >= @value_to_test
end

#hasObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/icemaker/filter.rb', line 30

def has
  if @value_to_test.instance_of? Hash then

    operator = @value_to_test.keys[0]
    values = @value_to_test.values[0]

    case operator
    when :or, :union_of
      values.any? { |value| @tag_value.downcase.has substring: value.downcase }
    when :and, :intersection_of
      values.all? { |value| @tag_value.downcase.has substring: value.downcase }
    end

  else
    @tag_value.downcase.has substring: @value_to_test.downcase
  end
end

#isObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/icemaker/filter.rb', line 52

def is
  if @value_to_test.instance_of? Hash then

    operator = @value_to_test.keys[0]
    values = @value_to_test.values[0]

    puts "error in filter, #{@tag_value} :is #{@value_to_test}; applying 'or' rather than 'and' for :is" if (operator == :and || operator == :intersection_of)

    values.any? { |value| @tag_value.downcase == value.downcase }
  else
    @tag_value.downcase == @value_to_test.downcase
  end
end

#ltObject



78
79
80
# File 'lib/icemaker/filter.rb', line 78

def lt
  @tag_value < @value_to_test
end

#lteObject



70
71
72
# File 'lib/icemaker/filter.rb', line 70

def lte
  @tag_value <= @value_to_test
end

#pass?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/icemaker/filter.rb', line 86

def pass?
  self.send @test
end

#regxObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/icemaker/filter.rb', line 7

def regx
  if @value_to_test.instance_of? Hash then

    operator = @value_to_test.keys[0]
    values = @value_to_test.values[0]

    case operator
    when :or, :union_of
      values.any? { |value| @tag_value =~ (Regexp.new value) }
    when :and, :intersection_of
      values.all? { |value| @tag_value =~ (Regexp.new value) }
    end

  else
    @tag_value =~ (Regexp.new @value_to_test)
  end

end

#satisfiesObject



26
27
28
# File 'lib/icemaker/filter.rb', line 26

def satisfies
  regx
end