Class: PaysonAPI::V1::OrderItem

Inherits:
Object
  • Object
show all
Defined in:
lib/payson_api/v1/order_item.rb

Constant Summary collapse

FORMAT_STRING =
'orderItemList.orderItem(%d).%s'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



8
9
10
# File 'lib/payson_api/v1/order_item.rb', line 8

def description
  @description
end

#quantityObject

Returns the value of attribute quantity.



8
9
10
# File 'lib/payson_api/v1/order_item.rb', line 8

def quantity
  @quantity
end

#skuObject

Returns the value of attribute sku.



8
9
10
# File 'lib/payson_api/v1/order_item.rb', line 8

def sku
  @sku
end

#taxObject

Returns the value of attribute tax.



8
9
10
# File 'lib/payson_api/v1/order_item.rb', line 8

def tax
  @tax
end

#unit_priceObject

Returns the value of attribute unit_price.



8
9
10
# File 'lib/payson_api/v1/order_item.rb', line 8

def unit_price
  @unit_price
end

Class Method Details

.parse(data) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/payson_api/v1/order_item.rb', line 26

def self.parse(data)
  [].tap do |order_items|
    i = 0
    while data[format(FORMAT_STRING, i, 'description')]
      order_items << new.tap do |item|
        item.description = CGI.unescape(data[format(FORMAT_STRING, i, 'description')].to_s)
        item.unit_price = data[format(FORMAT_STRING, i, 'unitPrice')]
        item.quantity = data[format(FORMAT_STRING, i, 'quantity')]
        item.tax = data[format(FORMAT_STRING, i, 'taxPercentage')]
        item.sku = data[format(FORMAT_STRING, i, 'sku')]
      end
      i += 1
    end
  end
end

.to_hash(order_items) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/payson_api/v1/order_item.rb', line 12

def self.to_hash(order_items)
  {}.tap do |hash|
    order_items.each_with_index do |item, index|
      hash.merge!({
                    format(FORMAT_STRING, index, 'description') => item.description,
                    format(FORMAT_STRING, index, 'unitPrice') => item.unit_price,
                    format(FORMAT_STRING, index, 'quantity') => item.quantity,
                    format(FORMAT_STRING, index, 'taxPercentage') => item.tax,
                    format(FORMAT_STRING, index, 'sku') => item.sku
                  })
    end
  end
end