Sha256: 01ed81510bdeab995ad724598f6bff4e344b4784333e4ef4370f6cc766b9c394

Contents?: true

Size: 1.13 KB

Versions: 34

Compression:

Stored size: 1.13 KB

Contents

dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'happymapper')

file_contents = File.read(dir + '/../spec/fixtures/pita.xml')

# The document `pita.xml` contains both a default namespace and the 'georss'
# namespace (for the 'point' element).
module PITA
  class Item
    include HappyMapper
    
    tag 'Item' # if you put class in module you need tag
    element :asin, String, :tag => 'ASIN'
    element :detail_page_url, String, :tag => 'DetailPageURL'
    element :manufacturer, String, :tag => 'Manufacturer', :deep => true
    # this is the only element that exists in a different namespace, so it
    # must be explicitly specified
    element :point, String, :tag => 'point', :namespace => 'georss'
  end

  class Items
    include HappyMapper
    
    tag 'Items' # if you put class in module you need tag
    element :total_results, Integer, :tag => 'TotalResults'
    element :total_pages, Integer, :tag => 'TotalPages'
    has_many :items, Item
  end
end

item = PITA::Items.parse(file_contents, :single => true)
item.items.each do |i|
  puts i.asin, i.detail_page_url, i.manufacturer, ''
end

Version data entries

34 entries across 34 versions & 12 rubygems

Version Path
happymapper-0.5.0 examples/amazon.rb
dam5s-happymapper-0.3.2 examples/amazon.rb
jimmyz-happymapper-0.3.1 examples/amazon.rb
jimmyz-happymapper-0.3.2 examples/amazon.rb
jimmyz-happymapper-0.3.3 examples/amazon.rb
jnunemaker-happymapper-0.2.1 examples/amazon.rb
jnunemaker-happymapper-0.2.2 examples/amazon.rb
jnunemaker-happymapper-0.2.3 examples/amazon.rb
jnunemaker-happymapper-0.2.4 examples/amazon.rb
jnunemaker-happymapper-0.2.5 examples/amazon.rb
kdonovan-happymapper-0.3.4 examples/amazon.rb
kdonovan-happymapper-0.3.5 examples/amazon.rb
lightningdb-happymapper-0.3.0 examples/amazon.rb
lightningdb-happymapper-0.3.1 examples/amazon.rb
lightningdb-happymapper-0.3.2 examples/amazon.rb
macasek-happymapper-0.2.5 examples/amazon.rb
macasek-happymapper-0.2.6 examples/amazon.rb
robmitch-happymapper-0.2.5 examples/amazon.rb
happymapper-0.4.1 examples/amazon.rb
happymapper-swanandp-0.4.0 examples/amazon.rb