Class: NewStoreApi::Condition

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/models/condition.rb

Overview

Represents a single filter condition.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(field = nil, operator = nil, value = nil) ⇒ Condition

Returns a new instance of Condition.



43
44
45
46
47
# File 'lib/new_store_api/models/condition.rb', line 43

def initialize(field = nil, operator = nil, value = nil)
  @field = field
  @operator = operator
  @value = value
end

Instance Attribute Details

#fieldString

TODO: Write general description for this method

Returns:

  • (String)


14
15
16
# File 'lib/new_store_api/models/condition.rb', line 14

def field
  @field
end

#operatorOperatorEnum

Supported filter operators.

Returns:



18
19
20
# File 'lib/new_store_api/models/condition.rb', line 18

def operator
  @operator
end

#valueObject

Supported filter operators.

Returns:

  • (Object)


22
23
24
# File 'lib/new_store_api/models/condition.rb', line 22

def value
  @value
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/new_store_api/models/condition.rb', line 50

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  field = hash.key?('field') ? hash['field'] : nil
  operator = hash.key?('operator') ? hash['operator'] : nil
  value = hash.key?('value') ? hash['value'] : nil

  # Create object from extracted values.
  Condition.new(field,
                operator,
                value)
end

.namesObject

A mapping from model property names to API property names.



25
26
27
28
29
30
31
# File 'lib/new_store_api/models/condition.rb', line 25

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['field'] = 'field'
  @_hash['operator'] = 'operator'
  @_hash['value'] = 'value'
  @_hash
end

.nullablesObject

An array for nullable fields



39
40
41
# File 'lib/new_store_api/models/condition.rb', line 39

def self.nullables
  []
end

.optionalsObject

An array for optional fields



34
35
36
# File 'lib/new_store_api/models/condition.rb', line 34

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Condition | Hash)

    value against the validation is performed.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/new_store_api/models/condition.rb', line 66

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.field,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.operator,
                              ->(val) { OperatorEnum.validate(val) }) and
        APIHelper.valid_type?(value.value,
                              ->(val) { val.instance_of? Object })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['field'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['operator'],
                            ->(val) { OperatorEnum.validate(val) }) and
      APIHelper.valid_type?(value['value'],
                            ->(val) { val.instance_of? Object })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



97
98
99
100
101
# File 'lib/new_store_api/models/condition.rb', line 97

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} field: #{@field.inspect}, operator: #{@operator.inspect}, value:"\
  " #{@value.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



91
92
93
94
# File 'lib/new_store_api/models/condition.rb', line 91

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} field: #{@field}, operator: #{@operator}, value: #{@value}>"
end