Class: XeroGateway::TrackingCategory

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

Defined Under Namespace

Classes: Option

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ TrackingCategory

Returns a new instance of TrackingCategory.



46
47
48
49
50
51
52
# File 'lib/xero_gateway/tracking_category.rb', line 46

def initialize(params = {})
  @options = []
  @all_options = []
  params.each do |k,v|
    self.send("#{k}=", v)
  end
end

Instance Attribute Details

#all_optionsObject

Returns the value of attribute all_options.



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

def all_options
  @all_options
end

#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

#statusObject

Returns the value of attribute status.



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

def status
  @status
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



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/xero_gateway/tracking_category.rb', line 88

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 "Status" then tracking_category.status = element.text
      when "Options" then
        element.children.each do |option_child|
          tracking_category.options << option_child.children.detect {|c| c.name == "Name"}.text
          tracking_category.all_options << Option.from_xml(option_child)
        end
      when "Option" then tracking_category.options << element.text
    end
  end
  tracking_category
end

Instance Method Details

#==(other) ⇒ Object



106
107
108
109
110
111
# File 'lib/xero_gateway/tracking_category.rb', line 106

def ==(other)
  [:tracking_category_id, :name, :options].each do |field|
    return false if send(field) != other.send(field)
  end
  return true
end

#optionObject



54
55
56
# File 'lib/xero_gateway/tracking_category.rb', line 54

def option
   options[0] if options.size == 1
end

#to_xml(b = Builder::XmlMarkup.new) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/xero_gateway/tracking_category.rb', line 58

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



80
81
82
83
84
85
86
# File 'lib/xero_gateway/tracking_category.rb', line 80

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