uva-happymapper 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. data/README.md +528 -0
  2. data/TODO +0 -0
  3. data/lib/happymapper.rb +617 -0
  4. data/lib/happymapper/attribute.rb +3 -0
  5. data/lib/happymapper/element.rb +3 -0
  6. data/lib/happymapper/item.rb +250 -0
  7. data/lib/happymapper/text_node.rb +3 -0
  8. data/spec/fixtures/address.xml +8 -0
  9. data/spec/fixtures/ambigous_items.xml +22 -0
  10. data/spec/fixtures/analytics.xml +61 -0
  11. data/spec/fixtures/analytics_profile.xml +127 -0
  12. data/spec/fixtures/atom.xml +19 -0
  13. data/spec/fixtures/commit.xml +52 -0
  14. data/spec/fixtures/current_weather.xml +89 -0
  15. data/spec/fixtures/dictionary.xml +20 -0
  16. data/spec/fixtures/family_tree.xml +21 -0
  17. data/spec/fixtures/inagy.xml +86 -0
  18. data/spec/fixtures/lastfm.xml +355 -0
  19. data/spec/fixtures/multiple_namespaces.xml +170 -0
  20. data/spec/fixtures/multiple_primitives.xml +5 -0
  21. data/spec/fixtures/pita.xml +133 -0
  22. data/spec/fixtures/posts.xml +23 -0
  23. data/spec/fixtures/product_default_namespace.xml +17 -0
  24. data/spec/fixtures/product_no_namespace.xml +10 -0
  25. data/spec/fixtures/product_single_namespace.xml +10 -0
  26. data/spec/fixtures/quarters.xml +19 -0
  27. data/spec/fixtures/radar.xml +21 -0
  28. data/spec/fixtures/statuses.xml +422 -0
  29. data/spec/fixtures/subclass_namespace.xml +50 -0
  30. data/spec/happymapper_attribute_spec.rb +21 -0
  31. data/spec/happymapper_element_spec.rb +21 -0
  32. data/spec/happymapper_item_spec.rb +115 -0
  33. data/spec/happymapper_spec.rb +968 -0
  34. data/spec/happymapper_text_node_spec.rb +21 -0
  35. data/spec/happymapper_to_xml_namespaces_spec.rb +196 -0
  36. data/spec/happymapper_to_xml_spec.rb +196 -0
  37. data/spec/ignay_spec.rb +95 -0
  38. data/spec/spec_helper.rb +7 -0
  39. data/spec/xpath_spec.rb +88 -0
  40. metadata +118 -0
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'happymapper')
4
+
5
+ def fixture_file(filename)
6
+ File.read(File.dirname(__FILE__) + "/fixtures/#{filename}")
7
+ end
@@ -0,0 +1,88 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ test_xml = %{
4
+ <rss>
5
+ <amazing:item xmlns:amazing="http://www.amazing.com/amazing" xmlns:different="http://www.different.com/different">
6
+ <amazing:title>Test XML</amazing:/title>
7
+ <different:link href="different_link" />
8
+ <amazing:link href="link_to_resources" />
9
+ <amazing:subitem>
10
+ <amazing:detail>I want to parse this</amazing:detail>
11
+ <amazing:more first="this one">more 1</amazing:more>
12
+ <amazing:more alternative="another one">more 2</amazing:more>
13
+ </amazing:subitem>
14
+ <amazing:baby>
15
+ <amazing:name>Jumbo</amazing:name>
16
+ </amazing:baby>
17
+ </amazing:item>
18
+ </rss>
19
+ }
20
+
21
+ class Item
22
+ include HappyMapper
23
+
24
+ tag 'item'
25
+ namespace 'amazing'
26
+
27
+ element :title, String
28
+ attribute :link, String, :xpath => 'amazing:link/@href'
29
+ has_one :different_link, String, :xpath => 'different:link/@href'
30
+ element :detail, String, :xpath => 'amazing:subitem/amazing:detail'
31
+ has_many :more_details_text, String, :xpath => 'amazing:subitem/amazing:more'
32
+ has_many :more_details, String, :xpath => 'amazing:subitem/amazing:more/@first|amazing:subitem/amazing:more/@alternative'
33
+ has_many :more_details_alternative, String, :xpath => 'amazing:subitem/amazing:more/@*'
34
+
35
+ has_one :baby, 'Baby', :name => 'baby', :namespace => 'amazing'
36
+
37
+ end
38
+
39
+ class Baby
40
+ include HappyMapper
41
+
42
+ has_one :name, String
43
+ end
44
+
45
+ describe HappyMapper do
46
+
47
+ it "should have a title" do
48
+ @item.title.should == "Test XML"
49
+ end
50
+
51
+ it "should find the link href value" do
52
+ @item.link.should == 'link_to_resources'
53
+ end
54
+
55
+ it "should find the link href value" do
56
+ @item.different_link.should == 'different_link'
57
+ end
58
+
59
+ it "should find this subitem based on the xpath" do
60
+ @item.detail.should == 'I want to parse this'
61
+ end
62
+
63
+ it "should find the subitems based on the xpath" do
64
+ @item.more_details_text.length.should == 2
65
+ @item.more_details_text.first.should == "more 1"
66
+ @item.more_details_text.last.should == "more 2"
67
+ end
68
+
69
+ it "should find the subitems based on the xpath" do
70
+ @item.more_details.length.should == 2
71
+ @item.more_details.first.should == "this one"
72
+ @item.more_details.last.should == "another one"
73
+ end
74
+
75
+ it "should find the subitems based on the xpath" do
76
+ @item.more_details.length.should == 2
77
+ @item.more_details_alternative.first.should == "this one"
78
+ @item.more_details_alternative.last.should == "another one"
79
+ end
80
+ it "should have a baby name" do
81
+ @item.baby.name.should == "Jumbo"
82
+ end
83
+
84
+ before(:all) do
85
+ @item = Item.parse(test_xml,:single => true)
86
+ end
87
+
88
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uva-happymapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.1
5
+ platform: ruby
6
+ authors:
7
+ - Damien Le Berrigaud
8
+ - John Nunemaker
9
+ - David Bolton
10
+ - Roland Swingler
11
+ - Etienne Vallette d'Osia
12
+ - Franklin Webber
13
+ - Molly Pickral
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-01 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: nokogiri
23
+ type: :runtime
24
+ version_requirement:
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.5.0
30
+ version:
31
+ - !ruby/object:Gem::Dependency
32
+ name: rspec
33
+ type: :development
34
+ version_requirement:
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: 1.3.0
40
+ version:
41
+ description: Object to XML Mapping Library, using Nokogiri 1.5.0 (fork from John Nunemaker's Happymapper)
42
+ email: mpc3c@virginia.edu
43
+ executables: []
44
+
45
+ extensions: []
46
+
47
+ extra_rdoc_files:
48
+ - README.md
49
+ - TODO
50
+ files:
51
+ - lib/happymapper.rb
52
+ - lib/happymapper/attribute.rb
53
+ - lib/happymapper/element.rb
54
+ - lib/happymapper/item.rb
55
+ - lib/happymapper/text_node.rb
56
+ - README.md
57
+ - TODO
58
+ has_rdoc: true
59
+ homepage: https://github.com/uvalib/happymapper
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.5
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Provides a simple way to map XML to Ruby Objects and back again.
86
+ test_files:
87
+ - spec/fixtures/address.xml
88
+ - spec/fixtures/ambigous_items.xml
89
+ - spec/fixtures/analytics.xml
90
+ - spec/fixtures/analytics_profile.xml
91
+ - spec/fixtures/atom.xml
92
+ - spec/fixtures/commit.xml
93
+ - spec/fixtures/current_weather.xml
94
+ - spec/fixtures/dictionary.xml
95
+ - spec/fixtures/family_tree.xml
96
+ - spec/fixtures/inagy.xml
97
+ - spec/fixtures/lastfm.xml
98
+ - spec/fixtures/multiple_namespaces.xml
99
+ - spec/fixtures/multiple_primitives.xml
100
+ - spec/fixtures/pita.xml
101
+ - spec/fixtures/posts.xml
102
+ - spec/fixtures/product_default_namespace.xml
103
+ - spec/fixtures/product_no_namespace.xml
104
+ - spec/fixtures/product_single_namespace.xml
105
+ - spec/fixtures/quarters.xml
106
+ - spec/fixtures/radar.xml
107
+ - spec/fixtures/statuses.xml
108
+ - spec/fixtures/subclass_namespace.xml
109
+ - spec/happymapper_attribute_spec.rb
110
+ - spec/happymapper_element_spec.rb
111
+ - spec/happymapper_item_spec.rb
112
+ - spec/happymapper_spec.rb
113
+ - spec/happymapper_text_node_spec.rb
114
+ - spec/happymapper_to_xml_namespaces_spec.rb
115
+ - spec/happymapper_to_xml_spec.rb
116
+ - spec/ignay_spec.rb
117
+ - spec/spec_helper.rb
118
+ - spec/xpath_spec.rb