Sha256: e6ea3db0228e5688820dfc80193bb53ee8fe36d50508fb6dc6c091c56ff561e0

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

module KashflowApi
    class SoapObject
        attr_accessor :hash
        
        def initialize(hash = nil)
            if hash
                @hash = hash
                build_field_hash
            else
                @hash = blank_object_hash
                build_field_hash
            end
        end
        
        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
        
        def self.build_from_soap(hash)
            self.new(hash)
        end
        
        private
        
        def build_field_hash
            @fields = {}
            @hash.keys.each do |key|
                @fields[key.downcase.to_sym] = key
            end
        end
    end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kashflow_api-0.0.3 lib/kashflow_api/soap_object.rb
kashflow_api-0.0.2 lib/kashflow_api/soap_object.rb
kashflow_api-0.0.1 lib/kashflow_api/soap_object.rb
kashflow_api-0.0.1rc1 lib/kashflow_api/soap_object.rb
kashflow_api-0.0.1pre lib/kashflow_api/soap_object.rb