Class: Everdeen::Criterion

Inherits:
Object
  • Object
show all
Defined in:
lib/everdeen/criterion.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Criterion

Returns a new instance of Criterion.



5
6
7
8
9
# File 'lib/everdeen/criterion.rb', line 5

def initialize(args = {})
  args.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



3
4
5
# File 'lib/everdeen/criterion.rb', line 3

def key
  @key
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/everdeen/criterion.rb', line 3

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/everdeen/criterion.rb', line 3

def value
  @value
end

Instance Method Details

#match_typeObject



11
12
13
# File 'lib/everdeen/criterion.rb', line 11

def match_type
  @match_type || 'exact'
end

#to_hashObject



15
16
17
18
19
20
21
22
23
# File 'lib/everdeen/criterion.rb', line 15

def to_hash
  base = { key: key, match_type: match_type, type: type }

  if query_param_type? && value.is_a?(Array)
    base.merge(values: value)
  else
    base.merge(value: value)
  end
end