Class: Honey::Order
- Inherits:
-
Object
- Object
- Honey::Order
- Defined in:
- lib/honey/order.rb
Instance Attribute Summary collapse
-
#address1 ⇒ Object
Returns the value of attribute address1.
-
#address2 ⇒ Object
Returns the value of attribute address2.
-
#city ⇒ Object
Returns the value of attribute city.
-
#country ⇒ Object
Returns the value of attribute country.
-
#date ⇒ Object
Returns the value of attribute date.
-
#emailaddress ⇒ Object
Returns the value of attribute emailaddress.
-
#first ⇒ Object
Returns the value of attribute first.
-
#instructions ⇒ Object
Returns the value of attribute instructions.
-
#items ⇒ Object
Returns the value of attribute items.
-
#last ⇒ Object
Returns the value of attribute last.
-
#phone ⇒ Object
Returns the value of attribute phone.
-
#reference ⇒ Object
Returns the value of attribute reference.
-
#shipby ⇒ Object
(also: #shipping)
Returns the value of attribute shipby.
-
#state ⇒ Object
Returns the value of attribute state.
-
#zip ⇒ Object
Returns the value of attribute zip.
Class Method Summary collapse
- .attr_accessor(*attributes) ⇒ Object
- .attributes ⇒ Object
- .shipping_option(carrier: :special, service:) ⇒ Object
- .shipping_option_from_api_code(api_code) ⇒ Object
Instance Method Summary collapse
- #attributes ⇒ Object
- #each_pair(&block) ⇒ Object
-
#initialize(args = {}) ⇒ Order
constructor
A new instance of Order.
- #invalid? ⇒ Boolean
- #present_attributes ⇒ Object
- #required_attributes ⇒ Object
- #shipping_option(*args) ⇒ Object
- #update(args = {}) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(args = {}) ⇒ Order
Returns a new instance of Order.
19 20 21 |
# File 'lib/honey/order.rb', line 19 def initialize(args = {}) update(args) end |
Instance Attribute Details
#address1 ⇒ Object
Returns the value of attribute address1.
17 18 19 |
# File 'lib/honey/order.rb', line 17 def address1 @address1 end |
#address2 ⇒ Object
Returns the value of attribute address2.
17 18 19 |
# File 'lib/honey/order.rb', line 17 def address2 @address2 end |
#city ⇒ Object
Returns the value of attribute city.
17 18 19 |
# File 'lib/honey/order.rb', line 17 def city @city end |
#country ⇒ Object
Returns the value of attribute country.
17 18 19 |
# File 'lib/honey/order.rb', line 17 def country @country end |
#date ⇒ Object
Returns the value of attribute date.
17 18 19 |
# File 'lib/honey/order.rb', line 17 def date @date end |
#emailaddress ⇒ Object
Returns the value of attribute emailaddress.
17 18 19 |
# File 'lib/honey/order.rb', line 17 def emailaddress @emailaddress end |
#first ⇒ Object
Returns the value of attribute first.
17 18 19 |
# File 'lib/honey/order.rb', line 17 def first @first end |
#instructions ⇒ Object
Returns the value of attribute instructions.
17 18 19 |
# File 'lib/honey/order.rb', line 17 def instructions @instructions end |
#items ⇒ Object
Returns the value of attribute items.
17 18 19 |
# File 'lib/honey/order.rb', line 17 def items @items end |
#last ⇒ Object
Returns the value of attribute last.
17 18 19 |
# File 'lib/honey/order.rb', line 17 def last @last end |
#phone ⇒ Object
Returns the value of attribute phone.
17 18 19 |
# File 'lib/honey/order.rb', line 17 def phone @phone end |
#reference ⇒ Object
Returns the value of attribute reference.
17 18 19 |
# File 'lib/honey/order.rb', line 17 def reference @reference end |
#shipby ⇒ Object Also known as: shipping
Returns the value of attribute shipby.
17 18 19 |
# File 'lib/honey/order.rb', line 17 def shipby @shipby end |
#state ⇒ Object
Returns the value of attribute state.
17 18 19 |
# File 'lib/honey/order.rb', line 17 def state @state end |
#zip ⇒ Object
Returns the value of attribute zip.
17 18 19 |
# File 'lib/honey/order.rb', line 17 def zip @zip end |
Class Method Details
.attr_accessor(*attributes) ⇒ Object
3 4 5 6 7 |
# File 'lib/honey/order.rb', line 3 def self.attr_accessor(*attributes) @attributes ||= [] @attributes.concat attributes super(*attributes) end |
.attributes ⇒ Object
9 10 11 |
# File 'lib/honey/order.rb', line 9 def self.attributes @attributes end |
.shipping_option(carrier: :special, service:) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/honey/order.rb', line 71 def self.shipping_option(carrier: :special, service:) carrier = carrier.to_s service = service.to_s unless = [carrier.downcase] raise Honey::Error, "'#{carrier}' isn't a valid carrier. Valid carriers are: #{.keys}" end unless option = [service.downcase] raise Honey::Error, "'#{service}' isn't a shipping option for #{carrier}. Valid options are: #{.keys}" end option end |
.shipping_option_from_api_code(api_code) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/honey/order.rb', line 87 def self.shipping_option_from_api_code(api_code) .each_pair do |carrier, | .each_pair do |service, code| return { carrier: carrier, service: service } if api_code == code end end nil end |
Instance Method Details
#attributes ⇒ Object
13 14 15 |
# File 'lib/honey/order.rb', line 13 def attributes self.class.attributes end |
#each_pair(&block) ⇒ Object
47 48 49 50 51 |
# File 'lib/honey/order.rb', line 47 def each_pair(&block) present_attributes.each do |key| yield(key, self.send(key), block) end end |
#invalid? ⇒ Boolean
57 58 59 |
# File 'lib/honey/order.rb', line 57 def invalid? !valid? end |
#present_attributes ⇒ Object
65 66 67 68 69 |
# File 'lib/honey/order.rb', line 65 def present_attributes attributes.collect do |attr| attr unless self.send(attr).nil? end.compact end |
#required_attributes ⇒ Object
61 62 63 |
# File 'lib/honey/order.rb', line 61 def required_attributes attributes - [:address2, :instructions, :phone] end |
#shipping_option(*args) ⇒ Object
83 84 85 |
# File 'lib/honey/order.rb', line 83 def shipping_option(*args) self.class.shipping_option(*args) end |
#update(args = {}) ⇒ Object
23 24 25 26 27 |
# File 'lib/honey/order.rb', line 23 def update(args = {}) args.each_pair do |key, value| self.send("#{key}=".to_sym, value) end end |
#valid? ⇒ Boolean
53 54 55 |
# File 'lib/honey/order.rb', line 53 def valid? (required_attributes - present_attributes).empty? end |