Class: XeroGateway::TaxRate

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

Constant Summary collapse

ATTRS =
{
  "Name"                  => :string, 
  "TaxType"               => :string,
  "CanApplyToAssets"      => :boolean,
  "CanApplyToEquity"      => :boolean,
  "CanApplyToExpenses"    => :boolean,
  "CanApplyToLiabilities" => :boolean,
  "CanApplyToRevenue"     => :boolean,
  "DisplayTaxRate"        => :float,
  "EffectiveRate"         => :float
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ TaxRate

Returns a new instance of TaxRate.



20
21
22
23
24
# File 'lib/xero_gateway/tax_rate.rb', line 20

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

Class Method Details

.from_xml(tax_rate_element) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/xero_gateway/tax_rate.rb', line 43

def self.from_xml(tax_rate_element)
  TaxRate.new.tap do |tax_rate|
    tax_rate_element.children.each do |element|
    
      attribute             = element.name
      underscored_attribute = element.name.underscore
    
      raise "Unknown attribute: #{attribute}" unless ATTRS.keys.include?(attribute)
    
      case (ATTRS[attribute])
        when :boolean then  tax_rate.send("#{underscored_attribute}=", (element.text == "true"))
        when :float   then  tax_rate.send("#{underscored_attribute}=", element.text.to_f)
        else                tax_rate.send("#{underscored_attribute}=", element.text)
      end
      
    end
  end
end

Instance Method Details

#==(other) ⇒ Object



26
27
28
29
30
31
# File 'lib/xero_gateway/tax_rate.rb', line 26

def ==(other)
  ATTRS.keys.map(&:underscore).each do |field|
    return false if send(field) != other.send(field)
  end
  return true
end

#to_xmlObject



33
34
35
36
37
38
39
40
41
# File 'lib/xero_gateway/tax_rate.rb', line 33

def to_xml
  b = Builder::XmlMarkup.new
  
  b.TaxRate do
    ATTRS.keys.each do |attr|
      eval("b.#{attr} '#{self.send(attr.underscore.to_sym)}'")
    end
  end
end