Class: IngramMicro::BaseElement
- Inherits:
-
Object
- Object
- IngramMicro::BaseElement
- Defined in:
- lib/ingram_micro/base_element.rb
Direct Known Subclasses
CreditCardInformation, Customer, Detail, MessageHeaderNoPW, MessageHeaderPW, MessageStatus, PurchaseOrderInformation, ReturnAuthorizationLineItem, ReturnAuthorizationOrderHeader, ReturnAuthorizationSubmission, SalesOrderHeader, SalesOrderLineItem, SalesOrderSubmission, ShipmentInformation, ShipmentStatus, ShipmentStatusLineItem
Instance Attribute Summary collapse
-
#element ⇒ Object
Returns the value of attribute element.
Instance Method Summary collapse
- #build(builder) ⇒ Object
-
#initialize(options = {}) ⇒ BaseElement
constructor
A new instance of BaseElement.
- #integer?(string) ⇒ Boolean
- #parse(message_hash) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ BaseElement
Returns a new instance of BaseElement.
5 6 7 8 9 10 11 12 |
# File 'lib/ingram_micro/base_element.rb', line 5 def initialize(={}) @element = {} self.defaults.each do |field, default| value = ([field] ? [field] : default) @element[field] = value end @element[:customer_id] ||= IngramMicro.configuration.customer_id end |
Instance Attribute Details
#element ⇒ Object
Returns the value of attribute element.
3 4 5 |
# File 'lib/ingram_micro/base_element.rb', line 3 def element @element end |
Instance Method Details
#build(builder) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/ingram_micro/base_element.rb', line 14 def build(builder) self.defaults.keys.each do |field| element_name = field.to_s.gsub('_', '-') element_value = @element[field] builder.send(element_name, element_value) end end |
#integer?(string) ⇒ Boolean
29 30 31 |
# File 'lib/ingram_micro/base_element.rb', line 29 def integer?(string) Integer(string) != nil rescue false end |
#parse(message_hash) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/ingram_micro/base_element.rb', line 22 def parse() defaults.each do |field| element_name = field.to_s.gsub('_', '-') @element[field] = [element_name] end end |