Class: Rubix::Condition

Inherits:
Model
  • Object
show all
Defined in:
lib/rubix/models/condition.rb

Instance Attribute Summary

Attributes inherited from Model

#id, #properties

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#after_create, all, all_params, all_request, #before_destroy, #before_update, #create, #create_request, #destroy, #destroy_params, #destroy_request, each, find, find_or_create, find_params, find_request, get_params, id_field, #id_field, list, #new_record?, properties, #request, request, resource_name, #resource_name, #save, #to_hash, #update, #update_params, #update_request, #validate, web_request, zabbix_attr, zabbix_define, zabbix_name

Methods included from Logs

#debug, #error, #fatal, #info, #warn

Constructor Details

#initialize(properties = nil) ⇒ Condition

Returns a new instance of Condition


61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rubix/models/condition.rb', line 61

def initialize properties=nil
  if properties.is_a?(Array)
    raise ArgumentError.new("Must provide a condition type, operator, and value when initializing a condition with an array.") unless properties.size == 3
    super({
            :type     => properties[0],
            :operator => properties[1],
            :value    => properties[2]
          })
  else
    super(properties || {})
  end
end

Class Method Details

.build(condition) ⇒ Object


86
87
88
89
90
91
92
93
# File 'lib/rubix/models/condition.rb', line 86

def self.build condition
  new({
        :id       => condition[id_field].to_i,
        :type     => self::TYPE_NAMES[condition['conditiontype'].to_i],
        :operator => self::OPERATOR_NAMES[condition['operator'].to_i],
        :value    => condition['value'].to_s
      })
end

Instance Method Details

#create_paramsObject

Requests ==


78
79
80
81
82
83
84
# File 'lib/rubix/models/condition.rb', line 78

def create_params
  {
    :conditiontype => self.class::TYPE_CODES[type],
    :operator      => self.class::OPERATOR_CODES[operator],
    :value         => value.to_s
  }
end