Class: KashflowApi::SoapObject

Inherits:
Object
  • Object
show all
Defined in:
lib/kashflow_api/soap_object.rb

Direct Known Subclasses

Customer, Invoice, Line, NominalCode, Receipt, Supplier

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = nil) ⇒ SoapObject

Returns a new instance of SoapObject.



5
6
7
8
9
10
11
12
13
# File 'lib/kashflow_api/soap_object.rb', line 5

def initialize(hash = nil)
    if hash
        @hash = hash
        build_field_hash
    else
        @hash = blank_object_hash
        build_field_hash
    end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, set = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/kashflow_api/soap_object.rb', line 15

def method_missing(method, set = nil)
    if @fields.keys.include? method
        @hash[@fields[method]]
    elsif method.to_s.scan(/.$/).join == "="
        if @fields.keys.include? method.to_s.gsub(/\=/,'').to_sym
            @hash[@fields[method.to_s.gsub(/\=/,'').to_sym]] = set
        end
    else
        super
    end
end

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



3
4
5
# File 'lib/kashflow_api/soap_object.rb', line 3

def hash
  @hash
end

Class Method Details

.build_from_soap(hash) ⇒ Object



27
28
29
# File 'lib/kashflow_api/soap_object.rb', line 27

def self.build_from_soap(hash)
    self.new(hash)
end