Class: EwayRapid::Models::LineItem
- Inherits:
-
Object
- Object
- EwayRapid::Models::LineItem
- Defined in:
- lib/eway_rapid/models/models.rb
Overview
Item information
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
-
#sku ⇒ Object
The stock keeping unit used to identify this line item.
-
#tax ⇒ Object
The tax amount that applies to this line item in cents.
-
#total ⇒ Object
The total amount (including tax) charged for this line item in the cents.
-
#unit_cost ⇒ Object
The unit cost of this line item in cents.
Class Method Summary collapse
- .from_array(array) ⇒ Object
- .from_hash(hash) ⇒ Object
- .from_json(json) ⇒ Object
- .to_array(array) ⇒ Object
- .to_hash(line_item) ⇒ Object
Instance Method Summary collapse
-
#calculate(unit_cost, unit_tax, quantity) ⇒ Object
Set the line item’s values so that the total and tax add up correctly.
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
93 94 95 |
# File 'lib/eway_rapid/models/models.rb', line 93 def description @description end |
#quantity ⇒ Object
Returns the value of attribute quantity.
94 95 96 |
# File 'lib/eway_rapid/models/models.rb', line 94 def quantity @quantity end |
#sku ⇒ Object
The stock keeping unit used to identify this line item
92 93 94 |
# File 'lib/eway_rapid/models/models.rb', line 92 def sku @sku end |
#tax ⇒ Object
The tax amount that applies to this line item in cents
100 101 102 |
# File 'lib/eway_rapid/models/models.rb', line 100 def tax @tax end |
#total ⇒ Object
The total amount (including tax) charged for this line item in the cents
103 104 105 |
# File 'lib/eway_rapid/models/models.rb', line 103 def total @total end |
#unit_cost ⇒ Object
The unit cost of this line item in cents
97 98 99 |
# File 'lib/eway_rapid/models/models.rb', line 97 def unit_cost @unit_cost end |
Class Method Details
.from_array(array) ⇒ Object
154 155 156 157 158 159 160 161 |
# File 'lib/eway_rapid/models/models.rb', line 154 def self.from_array(array) line_items = Array.new array.each {|line_item_hash| obj = from_hash(line_item_hash) line_items.push(obj) } line_items end |
.from_hash(hash) ⇒ Object
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/eway_rapid/models/models.rb', line 143 def self.from_hash(hash) line_item = LineItem.new line_item.sku = hash[Constants::SKU] line_item.description = hash[Constants::DESCRIPTION] line_item.quantity = hash[Constants::QUANTITY] line_item.unit_cost = hash[Constants::UNIT_COST] line_item.tax = hash[Constants::TAX] line_item.total = hash[Constants::TOTAL] line_item end |
.from_json(json) ⇒ Object
138 139 140 141 |
# File 'lib/eway_rapid/models/models.rb', line 138 def self.from_json(json) hash = JSON.parse(json) from_hash(hash) end |
.to_array(array) ⇒ Object
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/eway_rapid/models/models.rb', line 127 def self.to_array(array) line_items = [] if array array.each {|line_item_hash| obj = to_hash(line_item_hash) line_items.push(obj) } end line_items end |
.to_hash(line_item) ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'lib/eway_rapid/models/models.rb', line 118 def self.to_hash(line_item) { Constants::SKU => line_item.sku, Constants::DESCRIPTION => line_item.description, Constants::QUANTITY => line_item.quantity, Constants::UNIT_COST => line_item.unit_cost, Constants::TAX => line_item.tax, Constants::TOTAL => line_item.total } if line_item end |
Instance Method Details
#calculate(unit_cost, unit_tax, quantity) ⇒ Object
Set the line item’s values so that the total and tax add up correctly
111 112 113 114 115 116 |
# File 'lib/eway_rapid/models/models.rb', line 111 def calculate(unit_cost, unit_tax, quantity) if unit_cost && unit_tax && quantity tax = unit_tax * quantity quantity * unit_cost + tax end end |