Sha256: 7cf3ac7177b50716069e85da1743c6f895746d55eb31283b9b7b4fc5e7050004

Contents?: true

Size: 514 Bytes

Versions: 5

Compression:

Stored size: 514 Bytes

Contents

module Petfinder
  module XmlMapper

    def xml_attributes(*names)
      names.each { |name| xml_attribute(name) }
    end

    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

    def camel_case_lower(name)
      name.split('_').inject([]) { |buffer, e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
petfinder-1.0.4 lib/petfinder/xml_mapper.rb
petfinder-1.0.3 lib/petfinder/xml_mapper.rb
petfinder-1.0.2 lib/petfinder/xml_mapper.rb
petfinder-1.0.1 lib/petfinder/xml_mapper.rb
petfinder-1.0.0 lib/petfinder/xml_mapper.rb