Class: XeroGateway::Organisation

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

Constant Summary collapse

ATTRS =
{
  "Name" 	                => :string,     # Display name of organisation shown in Xero
  "LegalName"             => :string,	   # Organisation name shown on Reports
  "PaysTax" 	            => :boolean,    # Boolean to describe if organisation is registered with a local tax authority i.e. true, false
  "Version"   	          => :string,     # See Version Types
  "BaseCurrency"          => :string,     # Default currency for organisation. See Currency types
  "OrganisationType"      => :string,     # UNDOCUMENTED parameter, only returned for "real" (i.e non-demo) companies
  "OrganisationStatus"    => :string,   # UNDOCUMENTED parameter
  "IsDemoCompany"         => :boolean,    # UNDOCUMENTED parameter
  "APIKey"                => :string,     # UNDOCUMENTED paramater, returned if organisations are linked via Xero Network
  "CountryCode"           => :string,      # UNDOCUMENTED parameter
  "TaxNumber"             => :string,
  "FinancialYearEndDay"   => :string,
  "FinancialYearEndMonth" => :string,
  "PeriodLockDate"        => :string,
  "CreatedDateUTC"        => :string        
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Organisation

Returns a new instance of Organisation.



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

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

Class Method Details

.from_xml(organisation_element) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/xero_gateway/organisation.rb', line 49

def self.from_xml(organisation_element)
  Organisation.new.tap do |org|
    organisation_element.children.each do |element|
    
      attribute             = element.name
      underscored_attribute = element.name.underscore
    
      if ATTRS.keys.include?(attribute)
              
        case (ATTRS[attribute])
          when :boolean then  org.send("#{underscored_attribute}=", (element.text == "true"))
          when :float   then  org.send("#{underscored_attribute}=", element.text.to_f)
          else                org.send("#{underscored_attribute}=", element.text)
        end
        
      else
        
        warn "Ignoring unknown attribute: #{attribute}" 
        
      end
      
    end
  end
end

Instance Method Details

#==(other) ⇒ Object



32
33
34
35
36
37
# File 'lib/xero_gateway/organisation.rb', line 32

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

#to_xmlObject



39
40
41
42
43
44
45
46
47
# File 'lib/xero_gateway/organisation.rb', line 39

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