Class: Io::Flow::V0::Models::ReservationItem

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ ReservationItem

Returns a new instance of ReservationItem.



30227
30228
30229
30230
30231
30232
30233
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30227

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:item, :quantity], 'ReservationItem')
  @item = (x = opts.delete(:item); x.is_a?(::Io::Flow::V0::Models::ReservationItemReference) ? x : ::Io::Flow::V0::Models::ReservationItemReference.new(x))
  @quantity = HttpClient::Preconditions.assert_class('quantity', opts.delete(:quantity), Integer)
  @serials = (x = opts.delete(:serials); x.nil? ? nil : HttpClient::Preconditions.assert_class('serials', x, Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::ReservationSerialReference) ? x : ::Io::Flow::V0::Models::ReservationSerialReference.new(x)) })
end

Instance Attribute Details

#itemObject (readonly)

Returns the value of attribute item.



30225
30226
30227
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30225

def item
  @item
end

#quantityObject (readonly)

Returns the value of attribute quantity.



30225
30226
30227
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30225

def quantity
  @quantity
end

#serialsObject (readonly)

Returns the value of attribute serials.



30225
30226
30227
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30225

def serials
  @serials
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



30239
30240
30241
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30239

def copy(incoming={})
  ReservationItem.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
end

#to_hashObject



30243
30244
30245
30246
30247
30248
30249
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30243

def to_hash
  {
    :item => item.to_hash,
    :quantity => quantity,
    :serials => serials.nil? ? nil : serials.map { |o| o.to_hash }
  }
end

#to_jsonObject



30235
30236
30237
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30235

def to_json
  JSON.dump(to_hash)
end