Module: Petfinder::XmlMapper
Instance Method Summary collapse
- #camel_case_lower(name) ⇒ Object
- #xml_attribute(name, xml_name = nil) ⇒ Object
- #xml_attributes(*names) ⇒ Object
Instance Method Details
#camel_case_lower(name) ⇒ Object
16 17 18 |
# File 'lib/petfinder/xml_mapper.rb', line 16 def camel_case_lower(name) name.split('_').inject([]) { |buffer, e| buffer.push(buffer.empty? ? e : e.capitalize) }.join end |
#xml_attribute(name, xml_name = nil) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/petfinder/xml_mapper.rb', line 8 def xml_attribute(name, xml_name = nil) klass = self.name.split('::').last.downcase xml_name ||= camel_case_lower(name.to_s) define_method(name) do @xml.xpath("//#{klass}/#{xml_name}").text end end |
#xml_attributes(*names) ⇒ Object
4 5 6 |
# File 'lib/petfinder/xml_mapper.rb', line 4 def xml_attributes(*names) names.each { |name| xml_attribute(name) } end |