Sha256: 50949460169ad3b630b3122c2becec92e5a61731b007a5f0120863ae522e07de
Contents?: true
Size: 1.38 KB
Versions: 2
Compression:
Stored size: 1.38 KB
Contents
require "xml_mapper" require "date" class MyMapper < XmlMapper text :title, :version_title # 1:1 - maps xpaths title and version_title to attribute keys integer :released_in # converts value to an integer text :country, :after_map => :upcase # calls after_map method on extracted value if value responds to the method text :released_on, :after_map => :parse_date # calls after_map method defined in Mapper class when value does not respond boolean :allows_streaming # maps Y, y, yes, true => true, N, n, no, false => false within :artist do text :name => :artist_name # adds mapping for xpath "artist/name" integer :id => :artist_id end many "tracks/track" => :tracks do # maps xpath "tracks/track" to array with key :tracks text :title => :track_title integer :number => :track_number integer :disk => :disk_number exists :explicit_lyrics # checks if a node with the xpath exists end after_map do # is called after attributes are extracted, self references the extracted attributes self[:tracks_count] = self[:tracks].length end # to be used for after_map callbacks def parse_date(date_string) Date.parse(date_string) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
xml_mapper-0.3.3 | spec/my_mapper.rb |
xml_mapper-0.3.2 | spec/my_mapper.rb |