Class: XeroGateway::TrackingCategory
- Inherits:
-
Object
- Object
- XeroGateway::TrackingCategory
- Defined in:
- lib/xero_gateway/tracking_category.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#tracking_category_id ⇒ Object
Returns the value of attribute tracking_category_id.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(params = {}) ⇒ TrackingCategory
constructor
A new instance of TrackingCategory.
- #option ⇒ Object
- #to_xml(b = Builder::XmlMarkup.new) ⇒ Object
-
#to_xml_for_invoice_messages(b = Builder::XmlMarkup.new) ⇒ Object
When a tracking category is serialized as part of an invoice it may only have a single option, and the Options tag is omitted.
Constructor Details
#initialize(params = {}) ⇒ TrackingCategory
Returns a new instance of TrackingCategory.
23 24 25 26 27 28 |
# File 'lib/xero_gateway/tracking_category.rb', line 23 def initialize(params = {}) @options = [] params.each do |k,v| self.send("#{k}=", v) end end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
21 22 23 |
# File 'lib/xero_gateway/tracking_category.rb', line 21 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
21 22 23 |
# File 'lib/xero_gateway/tracking_category.rb', line 21 def @options end |
#tracking_category_id ⇒ Object
Returns the value of attribute tracking_category_id.
21 22 23 |
# File 'lib/xero_gateway/tracking_category.rb', line 21 def tracking_category_id @tracking_category_id end |
Class Method Details
.from_xml(tracking_category_element) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/xero_gateway/tracking_category.rb', line 64 def self.from_xml(tracking_category_element) tracking_category = TrackingCategory.new tracking_category_element.children.each do |element| case(element.name) when "TrackingCategoryID" then tracking_category.tracking_category_id = element.text when "Name" then tracking_category.name = element.text when "Options" then element.children.each do |option_child| tracking_category. << option_child.children.detect {|c| c.name == "Name"}.text end when "Option" then tracking_category. << element.text end end tracking_category end |
Instance Method Details
#==(other) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/xero_gateway/tracking_category.rb', line 80 def ==(other) [:tracking_category_id, :name, :options].each do |field| return false if send(field) != other.send(field) end return true end |
#option ⇒ Object
30 31 32 |
# File 'lib/xero_gateway/tracking_category.rb', line 30 def option [0] if .size == 1 end |
#to_xml(b = Builder::XmlMarkup.new) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/xero_gateway/tracking_category.rb', line 34 def to_xml(b = Builder::XmlMarkup.new) b.TrackingCategory { b.TrackingCategoryID tracking_category_id unless tracking_category_id.nil? b.Name self.name b.Options { if self..is_a?(Array) self..each do |option| b.Option { b.Name option } end else b.Option { b.Name self..to_s } end } } end |
#to_xml_for_invoice_messages(b = Builder::XmlMarkup.new) ⇒ Object
When a tracking category is serialized as part of an invoice it may only have a single option, and the Options tag is omitted
56 57 58 59 60 61 62 |
# File 'lib/xero_gateway/tracking_category.rb', line 56 def (b = Builder::XmlMarkup.new) b.TrackingCategory { b.TrackingCategoryID self.tracking_category_id unless tracking_category_id.nil? b.Name self.name b.Option self..is_a?(Array) ? self..first : self..to_s } end |