Class: XeroGateway::TrackingCategory

Inherits:
Object
  • Object
show all
Defined in:
lib/xero_gateway/tracking_category.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject

Returns the value of attribute name.



21
22
23
# File 'lib/xero_gateway/tracking_category.rb', line 21

def name
  @name
end

#optionsObject

Returns the value of attribute options.



21
22
23
# File 'lib/xero_gateway/tracking_category.rb', line 21

def options
  @options
end

#tracking_category_idObject

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.options << option_child.children.detect {|c| c.name == "Name"}.text
        end
      when "Option" then tracking_category.options << 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

#optionObject



30
31
32
# File 'lib/xero_gateway/tracking_category.rb', line 30

def option
   options[0] if options.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.options.is_a?(Array)
        self.options.each do |option|
          b.Option {
            b.Name option
          }
        end
      else
        b.Option {
          b.Name self.options.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 to_xml_for_invoice_messages(b = Builder::XmlMarkup.new)
  b.TrackingCategory {
    b.TrackingCategoryID self.tracking_category_id unless tracking_category_id.nil?
    b.Name self.name
    b.Option self.options.is_a?(Array) ? self.options.first : self.options.to_s 
  }      
end