Method: Raas::ItemModel.from_hash

Defined in:
lib/raas/models/item_model.rb

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/raas/models/item_model.rb', line 101

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  utid = hash['utid']
  reward_name = hash['rewardName']
  currency_code = hash['currencyCode']
  status = hash['status']
  value_type = hash['valueType']
  reward_type = hash['rewardType']
  created_date = APIHelper.rfc3339(hash['createdDate']) if
    hash['createdDate']
  last_update_date = APIHelper.rfc3339(hash['lastUpdateDate']) if
    hash['lastUpdateDate']
  countries = hash['countries']
  min_value = hash['minValue']
  max_value = hash['maxValue']
  face_value = hash['faceValue']

  # Create object from extracted values.
  ItemModel.new(utid,
                reward_name,
                currency_code,
                status,
                value_type,
                reward_type,
                created_date,
                last_update_date,
                countries,
                min_value,
                max_value,
                face_value)
end