Module: Sem4rSoap::SoapAttributes

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



45
46
47
# File 'lib/sem4r_soap/soap_attributes.rb', line 45

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#_from_element(el) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/sem4r_soap/soap_attributes.rb', line 61

def _from_element(el)
  self.class.attributes.each do |a|
    unless a.enum?
      value = el.at_xpath(a.xpath)
      __send__ a.name, value.text.strip unless value.nil?
    end
  end
  self
end

#_to_sObject



71
72
73
74
75
# File 'lib/sem4r_soap/soap_attributes.rb', line 71

def _to_s
  self.class.attributes.map do |a|
    if a.enum? then "" else self.send(a.name) end
  end.join(' ')
end

#_to_xml(tag) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/sem4r_soap/soap_attributes.rb', line 49

def _to_xml(tag)
  builder = Builder::XmlMarkup.new
  builder.tag!(tag) do |t|
    self.class.attributes.each do |a|
      unless a.enum?
        value = self.send(a.name)
        t.__send__(a.xpath, value) unless value.nil? # value could be a boolean so 'if value' is wrong
      end
    end
  end
end