representable 0.0.1.alpha1 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/README.rdoc +58 -153
  2. data/lib/representable.rb +18 -42
  3. data/lib/representable/bindings/json_bindings.rb +69 -0
  4. data/lib/representable/bindings/xml_bindings.rb +152 -0
  5. data/lib/representable/definition.rb +1 -12
  6. data/lib/representable/json.rb +66 -0
  7. data/lib/representable/version.rb +1 -1
  8. data/lib/representable/xml.rb +32 -38
  9. data/representable.gemspec +3 -2
  10. data/test/bindings_test.rb +110 -0
  11. data/test/json_test.rb +130 -0
  12. data/test/{roxml_test.rb → representable_test.rb} +28 -9
  13. data/test/test_helper.rb +2 -0
  14. data/test/xml_test.rb +192 -0
  15. metadata +32 -105
  16. data/History.txt +0 -354
  17. data/TODO +0 -37
  18. data/VERSION +0 -1
  19. data/examples/amazon.rb +0 -35
  20. data/examples/current_weather.rb +0 -27
  21. data/examples/dashed_elements.rb +0 -20
  22. data/examples/library.rb +0 -40
  23. data/examples/posts.rb +0 -27
  24. data/examples/rails.rb +0 -70
  25. data/examples/twitter.rb +0 -37
  26. data/examples/xml/active_record.xml +0 -70
  27. data/examples/xml/amazon.xml +0 -133
  28. data/examples/xml/current_weather.xml +0 -89
  29. data/examples/xml/dashed_elements.xml +0 -52
  30. data/examples/xml/posts.xml +0 -23
  31. data/examples/xml/twitter.xml +0 -422
  32. data/lib/representable/references.rb +0 -153
  33. data/spec/definition_spec.rb +0 -495
  34. data/spec/examples/active_record_spec.rb +0 -41
  35. data/spec/examples/amazon_spec.rb +0 -54
  36. data/spec/examples/current_weather_spec.rb +0 -37
  37. data/spec/examples/dashed_elements_spec.rb +0 -20
  38. data/spec/examples/library_spec.rb +0 -46
  39. data/spec/examples/post_spec.rb +0 -24
  40. data/spec/examples/twitter_spec.rb +0 -32
  41. data/spec/roxml_integration_test.rb +0 -289
  42. data/spec/roxml_spec.rb +0 -372
  43. data/spec/shared_specs.rb +0 -15
  44. data/spec/spec_helper.rb +0 -5
  45. data/spec/support/libxml.rb +0 -3
  46. data/spec/support/nokogiri.rb +0 -3
  47. data/spec/xml/array_spec.rb +0 -36
  48. data/spec/xml/attributes_spec.rb +0 -71
  49. data/spec/xml/encoding_spec.rb +0 -53
  50. data/spec/xml/namespace_spec.rb +0 -270
  51. data/spec/xml/namespaces_spec.rb +0 -67
  52. data/spec/xml/object_spec.rb +0 -82
  53. data/spec/xml/parser_spec.rb +0 -21
  54. data/spec/xml/text_spec.rb +0 -71
  55. data/test/fixtures/book_malformed.xml +0 -5
  56. data/test/fixtures/book_pair.xml +0 -8
  57. data/test/fixtures/book_text_with_attribute.xml +0 -5
  58. data/test/fixtures/book_valid.xml +0 -5
  59. data/test/fixtures/book_with_authors.xml +0 -7
  60. data/test/fixtures/book_with_contributions.xml +0 -9
  61. data/test/fixtures/book_with_contributors.xml +0 -7
  62. data/test/fixtures/book_with_contributors_attrs.xml +0 -7
  63. data/test/fixtures/book_with_default_namespace.xml +0 -9
  64. data/test/fixtures/book_with_depth.xml +0 -6
  65. data/test/fixtures/book_with_octal_pages.xml +0 -4
  66. data/test/fixtures/book_with_publisher.xml +0 -7
  67. data/test/fixtures/book_with_wrapped_attr.xml +0 -3
  68. data/test/fixtures/dictionary_of_attr_name_clashes.xml +0 -8
  69. data/test/fixtures/dictionary_of_attrs.xml +0 -6
  70. data/test/fixtures/dictionary_of_guarded_names.xml +0 -6
  71. data/test/fixtures/dictionary_of_mixeds.xml +0 -4
  72. data/test/fixtures/dictionary_of_name_clashes.xml +0 -10
  73. data/test/fixtures/dictionary_of_names.xml +0 -4
  74. data/test/fixtures/dictionary_of_texts.xml +0 -10
  75. data/test/fixtures/library.xml +0 -30
  76. data/test/fixtures/library_uppercase.xml +0 -30
  77. data/test/fixtures/muffins.xml +0 -3
  78. data/test/fixtures/nameless_ageless_youth.xml +0 -2
  79. data/test/fixtures/node_with_attr_name_conflicts.xml +0 -1
  80. data/test/fixtures/node_with_name_conflicts.xml +0 -4
  81. data/test/fixtures/numerology.xml +0 -4
  82. data/test/fixtures/person.xml +0 -1
  83. data/test/fixtures/person_with_guarded_mothers.xml +0 -13
  84. data/test/fixtures/person_with_mothers.xml +0 -10
  85. data/test/mocks/dictionaries.rb +0 -57
  86. data/test/mocks/mocks.rb +0 -279
  87. data/test/support/fixtures.rb +0 -11
  88. data/test/unit/definition_test.rb +0 -235
  89. data/test/unit/deprecations_test.rb +0 -24
  90. data/test/unit/to_xml_test.rb +0 -81
  91. data/test/unit/xml_attribute_test.rb +0 -39
  92. data/test/unit/xml_block_test.rb +0 -81
  93. data/test/unit/xml_bool_test.rb +0 -122
  94. data/test/unit/xml_convention_test.rb +0 -150
  95. data/test/unit/xml_hash_test.rb +0 -115
  96. data/test/unit/xml_initialize_test.rb +0 -49
  97. data/test/unit/xml_name_test.rb +0 -141
  98. data/test/unit/xml_namespace_test.rb +0 -31
  99. data/test/unit/xml_object_test.rb +0 -206
  100. data/test/unit/xml_required_test.rb +0 -94
  101. data/test/unit/xml_text_test.rb +0 -71
  102. data/website/index.html +0 -98
@@ -1,21 +0,0 @@
1
- require_relative './../spec_helper.rb'
2
-
3
- describe ROXML::XML do
4
- it "should raise on malformed xml" do
5
- if ROXML::XML_PARSER == 'libxml' # nokogiri is less strict and auto-closes for some reason
6
- proc { Book.from_xml(fixture(:book_malformed)) }.should raise_error(LibXML::XML::Error)
7
- end
8
- end
9
-
10
- it "should escape invalid characters on output to text node" do
11
- node = ROXML::XML.new_node("entities")
12
- ROXML::XML.set_content(node, " < > ' \" & ")
13
- node.to_s.should == "<entities> &lt; &gt; ' \" &amp; </entities>"
14
- end
15
-
16
- it "should esape invalid characters for attribute name" do
17
- node = ROXML::XML.new_node("attr_holder")
18
- ROXML::XML.set_attribute(node, "entities", "\"'<>&")
19
- node.to_s.should == %{<attr_holder entities="&quot;'&lt;&gt;&amp;"/>}
20
- end
21
- end
@@ -1,71 +0,0 @@
1
- require_relative './../spec_helper'
2
-
3
- describe ROXML::XMLTextRef do
4
- before do
5
- @xml = ROXML::XML.parse_string %(
6
- <myxml>
7
- <node>
8
- <name>first</name>
9
- <name>second</name>
10
- <name>third</name>
11
- </node>
12
- </myxml>)
13
- end
14
-
15
- context "plain vanilla" do
16
- before do
17
- @ref = ROXML::XMLTextRef.new(OpenStruct.new(:name => 'name', :wrapper => 'node', :array? => false), RoxmlObject.new)
18
- end
19
-
20
- it "should return one instance" do
21
- @ref.value_in(@xml).should == "first"
22
- end
23
- it "should output one instance"
24
- end
25
-
26
- context "with :as => []" do
27
- before do
28
- @ref = ROXML::XMLTextRef.new(OpenStruct.new(:name => 'name', :wrapper => 'node', :array? => true), RoxmlObject.new)
29
- end
30
-
31
- it "should collect all instances" do
32
- @ref.value_in(@xml).should == ["first", "second", "third"]
33
- end
34
-
35
- it "should output all instances" do
36
- xml = ROXML::XML.new_node('myxml')
37
- @ref.update_xml(xml, ["first", "second", "third"])
38
- xml.to_s.squeeze(' ').should == @xml.root.to_s.squeeze(' ')
39
- end
40
- end
41
-
42
- context "when the namespaces are different" do
43
- before do
44
- @xml = ROXML::XML.parse_string %(
45
- <myxml xmlns="http://example.com/three" xmlns:one="http://example.com/one" xmlns:two="http://example.com/two">
46
- <node>
47
- <one:name>first</one:name>
48
- <two:name>second</two:name>
49
- <name>third</name>
50
- </node>
51
- </myxml>)
52
- end
53
-
54
- context "with :namespace => '*'" do
55
- before do
56
- @ref = ROXML::XMLTextRef.new(OpenStruct.new(:name => 'name', :wrapper => 'node', :array? => true, :namespace => '*'), RoxmlObject.new)
57
- end
58
-
59
- it "should collect all instances" do
60
- @ref.value_in(@xml).should == ["first", "second", "third"]
61
- end
62
-
63
- it "should output all instances with namespaces" do
64
- pending "Full namespace write support"
65
- xml = ROXML::XML.new_node('myxml')
66
- @ref.update_xml(xml, ["first", "second", "third"])
67
- xml.should == @xml.root
68
- end
69
- end
70
- end
71
- end
@@ -1,5 +0,0 @@
1
- <book isbn="0201710897">
2
- <title>The PickAxe<title>
3
- <description><![CDATA[Probably the best Ruby book out there]]></description>
4
- <author>David Thomas, Andrew Hunt, Dave Thomas</author>
5
- </book>
@@ -1,8 +0,0 @@
1
- <book isbn="0974514055">
2
- <title>Programming Ruby - 2nd Edition</title>
3
- <description>Second edition of the great book out there</description>
4
- <book isbn="0974514055">
5
- <title>Agile Web Development with Rails</title>
6
- <description>Jolt winning original Ruby on Rails book</description>
7
- </book>
8
- </book>
@@ -1,5 +0,0 @@
1
- <book ISBN="0201710897">
2
- <title>The PickAxe</title>
3
- <description><![CDATA[Probably the best Ruby book out there]]></description>
4
- <author role="primary">David Thomas</author>
5
- </book>
@@ -1,5 +0,0 @@
1
- <book ISBN="0201710897">
2
- <title>The PickAxe</title>
3
- <description><![CDATA[Probably the best Ruby book out there]]></description>
4
- <author>David Thomas, Andrew Hunt &amp; Dave Thomas</author>
5
- <pagecount>357</pagecount></book>
@@ -1,7 +0,0 @@
1
- <book ISBN="0201710897">
2
- <title>The PickAxe</title>
3
- <description><![CDATA[Probably the best Ruby book out there]]></description>
4
- <author>David Thomas</author>
5
- <author>Andrew Hunt</author>
6
- <author>Dave Thomas</author>
7
- </book>
@@ -1,9 +0,0 @@
1
- <book isbn="0974514055">
2
- <title>Programming Ruby - 2nd Edition</title>
3
- <description>Second edition of the great book out there</description>
4
- <contributions>
5
- <contributor role="author"><name>David Thomas</name></contributor>
6
- <contributor role="supporting author"><name>Andrew Hunt</name></contributor>
7
- <contributor role="supporting author"><name>Chad Fowler</name></contributor>
8
- </contributions>
9
- </book>
@@ -1,7 +0,0 @@
1
- <book isbn="0974514055">
2
- <title>Programming Ruby - 2nd Edition</title>
3
- <description>Second edition of the great book out there</description>
4
- <contributor role="author"><name>David Thomas</name></contributor>
5
- <contributor role="supporting author"><name>Andrew Hunt</name></contributor>
6
- <contributor role="supporting author"><name>Chad Fowler</name></contributor>
7
- </book>
@@ -1,7 +0,0 @@
1
- <book isbn="0974514055">
2
- <title>Programming Ruby - 2nd Edition</title>
3
- <description>Second edition of the great book out there</description>
4
- <contributor role="author" name="David Thomas" />
5
- <contributor role="supporting author" name="Andrew Hunt" />
6
- <contributor role="supporting author" name="Chad Fowler" />
7
- </book>
@@ -1,9 +0,0 @@
1
- <book xmlns="http://booknamespace.org" isbn="0974514055">
2
- <title>Programming Ruby - 2nd Edition</title>
3
- <description>Second edition of the great book out there</description>
4
- <contributions>
5
- <contributor role="author"><name>David Thomas</name></contributor>
6
- <contributor role="supporting author"><name>Andrew Hunt</name></contributor>
7
- <contributor role="supporting author"><name>Chad Fowler</name></contributor>
8
- </contributions>
9
- </book>
@@ -1,6 +0,0 @@
1
- <book ISBN="0201710897">
2
- <title>The PickAxe</title>
3
- <description><![CDATA[Probably the best Ruby book out there]]></description>
4
- <author>David Thomas, Andrew Hunt, Dave Thomas</author>
5
- <depth units="hundredths-meters">1130</depth>
6
- </book>
@@ -1,4 +0,0 @@
1
- <bookwithoctalpages>
2
- <pages_with_to_xml_proc>0357</pages_with_to_xml_proc>
3
- <pages_with_type>0357</pages_with_type>
4
- </bookwithoctalpages>
@@ -1,7 +0,0 @@
1
- <book isbn="0974514055">
2
- <title>Programming Ruby - 2nd Edition</title>
3
- <description>Second edition of the great book out there</description>
4
- <publisher>
5
- <name>Pragmatic Bookshelf</name>
6
- </publisher>
7
- </book>
@@ -1,3 +0,0 @@
1
- <book>
2
- <ids ISBN="0974514055" />
3
- </book>
@@ -1,8 +0,0 @@
1
- <dictionary>
2
- <definition name="quaquaversally">
3
- <content>adjective: (of a geological formation) sloping downward from the center in all directions.</content>
4
- </definition>
5
- <definition name="tergiversate">
6
- <content>To use evasions or ambiguities; equivocate.</content>
7
- </definition>
8
- </dictionary>
@@ -1,6 +0,0 @@
1
- <dictionary>
2
- <definitions>
3
- <definition dt="quaquaversally" dd="adjective: (of a geological formation) sloping downward from the center in all directions." />
4
- <definition dt="tergiversate" dd="To use evasions or ambiguities; equivocate." />
5
- </definitions>
6
- </dictionary>
@@ -1,6 +0,0 @@
1
- <dictionary>
2
- <definitions>
3
- <quaquaversally>adjective: (of a geological formation) sloping downward from the center in all directions.</quaquaversally>
4
- <tergiversate>To use evasions or ambiguities; equivocate.</tergiversate>
5
- </definitions>
6
- </dictionary>
@@ -1,4 +0,0 @@
1
- <dictionary>
2
- <definition word="quaquaversally">adjective: (of a geological formation) sloping downward from the center in all directions.</definition>
3
- <definition word="tergiversate">To use evasions or ambiguities; equivocate.</definition>
4
- </dictionary>
@@ -1,10 +0,0 @@
1
- <dictionary>
2
- <definition>
3
- <name>quaquaversally</name>
4
- <content>adjective: (of a geological formation) sloping downward from the center in all directions.</content>
5
- </definition>
6
- <definition>
7
- <name>tergiversate</name>
8
- <content>To use evasions or ambiguities; equivocate.</content>
9
- </definition>
10
- </dictionary>
@@ -1,4 +0,0 @@
1
- <dictionary>
2
- <quaquaversally>adjective: (of a geological formation) sloping downward from the center in all directions.</quaquaversally>
3
- <tergiversate>To use evasions or ambiguities; equivocate.</tergiversate>
4
- </dictionary>
@@ -1,10 +0,0 @@
1
- <dictionary>
2
- <definition>
3
- <word>quaquaversally</word>
4
- <meaning>adjective: (of a geological formation) sloping downward from the center in all directions.</meaning>
5
- </definition>
6
- <definition>
7
- <word>tergiversate</word>
8
- <meaning>To use evasions or ambiguities; equivocate.</meaning>
9
- </definition>
10
- </dictionary>
@@ -1,30 +0,0 @@
1
- <library>
2
- <name>Ruby library</name>
3
- <book isbn="0974514055">
4
- <title>Programming Ruby - 2nd Edition</title>
5
- <description>Second edition of the great book out there</description>
6
- <contributions>
7
- <contributor role="author">
8
- <name>David Thomas</name>
9
- </contributor>
10
- <contributor role="supporting author">
11
- <name>Andrew Hunt</name>
12
- </contributor>
13
- <contributor role="supporting author">
14
- <name>Chad Fowler</name>
15
- </contributor>
16
- </contributions>
17
- </book>
18
- <book isbn="0974514055">
19
- <title>Agile Web Development with Rails</title>
20
- <description>Jolt winning original Ruby on Rails book</description>
21
- <contributions>
22
- <contributor role="author">
23
- <name>David Thomas</name>
24
- </contributor>
25
- <contributor role="author">
26
- <name>David Heinemeier Hansson</name>
27
- </contributor>
28
- </contributions>
29
- </book>
30
- </library>
@@ -1,30 +0,0 @@
1
- <library>
2
- <NAME>Ruby library</NAME>
3
- <BOOK isbn="0974514055">
4
- <title>Programming Ruby - 2nd Edition</title>
5
- <description>Second edition of the great book out there</description>
6
- <contributions>
7
- <contributor role="author">
8
- <name>David Thomas</name>
9
- </contributor>
10
- <contributor role="supporting author">
11
- <name>Andrew Hunt</name>
12
- </contributor>
13
- <contributor role="supporting author">
14
- <name>Chad Fowler</name>
15
- </contributor>
16
- </contributions>
17
- </BOOK>
18
- <BOOK isbn="0974514055">
19
- <title>Agile Web Development with Rails</title>
20
- <description>Jolt winning original Ruby on Rails book</description>
21
- <contributions>
22
- <contributor role="author">
23
- <name>David Thomas</name>
24
- </contributor>
25
- <contributor role="author">
26
- <name>David Heinemeier Hansson</name>
27
- </contributor>
28
- </contributions>
29
- </BOOK>
30
- </library>
@@ -1,3 +0,0 @@
1
- <muffins>
2
- <bakers_dozens>3</bakers_dozens>
3
- </muffins>
@@ -1,2 +0,0 @@
1
- <person>
2
- </person>
@@ -1 +0,0 @@
1
- <node content="Just junk... really" name="Cartwheel" />
@@ -1,4 +0,0 @@
1
- <node>
2
- <content>Just junk... really</content>
3
- <name>Cartwheel</name>
4
- </node>
@@ -1,4 +0,0 @@
1
- <numerology>
2
- <prediction number="13" meaning="A bad number" />
3
- <prediction number="7" meaning="A good number" />
4
- </numerology>
@@ -1 +0,0 @@
1
- <person>Ben Franklin</person>
@@ -1,13 +0,0 @@
1
- <person>
2
- <name>Ben &quot;Benji&quot; Franklin</name>
3
- <mother>
4
- <person>
5
- <name>Abiah &apos;Abby&apos; Folger</name>
6
- <mother>
7
- <person>
8
- <name>Madeup Mother &lt; the third &gt;</name>
9
- </person>
10
- </mother>
11
- </person>
12
- </mother>
13
- </person>
@@ -1,10 +0,0 @@
1
- <person>
2
- <name>Ben Franklin</name>
3
- <mother>
4
- <name>Abiah Folger</name>
5
- <mother>
6
- <name>Madeup Mother</name>
7
- </mother>
8
- </mother>
9
- </person>
10
-
@@ -1,57 +0,0 @@
1
- require_relative "./../../lib/roxml"
2
-
3
- class DictionaryOfAttrs
4
- include ROXML
5
-
6
- xml_name :dictionary
7
- xml_reader :definitions, :as => {:key => '@dt',
8
- :value => '@dd'}, :in => :definitions
9
- end
10
-
11
- class DictionaryOfTexts
12
- include ROXML
13
-
14
- xml_name :dictionary
15
- xml_reader :definitions, :as => {:key => :word,
16
- :value => :meaning}
17
- end
18
-
19
- class DictionaryOfMixeds
20
- include ROXML
21
-
22
- xml_name :dictionary
23
- xml_reader :definitions, :as => {:key => '@word',
24
- :value => :content}
25
- end
26
-
27
- class DictionaryOfNames
28
- include ROXML
29
-
30
- xml_name :dictionary
31
- xml_reader :definitions, :as => {:key => :name,
32
- :value => :content}
33
- end
34
-
35
- class DictionaryOfGuardedNames
36
- include ROXML
37
-
38
- xml_name :dictionary
39
- xml_reader :definitions, :as => {:key => :name,
40
- :value => :content}, :in => :definitions
41
- end
42
-
43
- class DictionaryOfNameClashes
44
- include ROXML
45
-
46
- xml_name :dictionary
47
- xml_reader :definitions, :as => {:key => 'name',
48
- :value => 'content'}, :from => :definition
49
- end
50
-
51
- class DictionaryOfAttrNameClashes
52
- include ROXML
53
-
54
- xml_name :dictionary
55
- xml_reader :definitions, :as => {:key => '@name',
56
- :value => 'content'}, :from => :definition
57
- end
@@ -1,279 +0,0 @@
1
- require_relative "./../../lib/roxml"
2
-
3
- class Muffins
4
- include ROXML
5
-
6
- xml_reader(:count, :from => 'bakers_dozens') {|val| val.to_i * 13 }
7
- end
8
-
9
- class MuffinsWithStackedBlocks
10
- include ROXML
11
-
12
- xml_reader(:count, :from => 'bakers_dozens', :as => Integer) {|val| val * 13 }
13
- end
14
-
15
- class Numerology
16
- include ROXML
17
-
18
- xml_reader :predictions, :as => {:key => '@number', :value => '@meaning'} do |k, v|
19
- [Integer(k), v]
20
- end
21
- end
22
-
23
- class Contributor
24
- include ROXML
25
-
26
- xml_reader :role, :from => :attr
27
- xml_reader :name
28
- end
29
-
30
- class WriteableContributor
31
- include ROXML
32
-
33
- xml_accessor :role, :from => :attr
34
- xml_accessor :name
35
- end
36
-
37
- class Book
38
- include ROXML
39
-
40
- xml_accessor :isbn, :from => '@ISBN'
41
- xml_reader :title
42
- xml_reader :description, :cdata => true
43
- xml_reader :author
44
- xml_accessor :pages, :from => 'pagecount', :as => Integer
45
- end
46
-
47
- class BookWithRequired
48
- include ROXML
49
-
50
- xml_accessor :isbn, :from => '@ISBN', :required => true
51
- xml_reader :title, :required => true
52
- xml_reader :contributors, :as => [Contributor], :in => 'contributor_array', :required => true
53
- xml_reader :contributor_hash, :as => {:key => '@role', :value => '@name'},
54
- :from => 'contributor', :in => 'contributor_hash', :required => true
55
- end
56
-
57
- class BookWithAttrFrom
58
- include ROXML
59
-
60
- xml_accessor :isbn, :from => '@ISBN'
61
- end
62
-
63
- class BookWithWrappedAttr
64
- include ROXML
65
-
66
- xml_name :book
67
- xml_accessor :isbn, :from => '@ISBN', :in => 'ids'
68
- end
69
-
70
- class Measurement
71
- include ROXML
72
-
73
- xml_reader :units, :from => :attr
74
- xml_reader :value, :from => :content, :as => Float
75
-
76
- def initialize(value = 0, units = 'pixels')
77
- @value = Float(value)
78
- @units = units.to_s
79
- normalize_hundredths
80
- end
81
-
82
- def to_s
83
- "#{value} #{units}"
84
- end
85
-
86
- def ==(other)
87
- other.units == @units && other.value == @value
88
- end
89
-
90
- private
91
- def after_parse
92
- normalize_hundredths
93
- end
94
-
95
- def normalize_hundredths
96
- if @units.starts_with? 'hundredths-'
97
- @value /= 100
98
- @units = @units.split('hundredths-')[1]
99
- end
100
- end
101
- end
102
-
103
- class BookWithDepth
104
- include ROXML
105
-
106
- xml_reader :isbn, :from => '@ISBN'
107
- xml_reader :title
108
- xml_reader :description, :cdata => true
109
- xml_reader :author
110
- xml_reader :depth, :as => Measurement
111
- end
112
-
113
- class Author
114
- include ROXML
115
-
116
- xml_reader :role, :from => :attr
117
- xml_reader :text, :from => :content
118
- end
119
-
120
- class BookWithAuthors
121
- include ROXML
122
-
123
- xml_name :book
124
- xml_reader :isbn, :from => '@ISBN'
125
- xml_reader :title
126
- xml_reader :description, :cdata => true
127
- xml_reader :authors, :as => []
128
- end
129
-
130
- class BookWithAuthorTextAttribute
131
- include ROXML
132
-
133
- xml_name :book
134
- xml_reader :isbn, :from => '@ISBN'
135
- xml_reader :title
136
- xml_reader :description, :cdata => true
137
- xml_reader :author, :as => Author
138
- end
139
-
140
- class BookWithContributions
141
- include ROXML
142
-
143
- xml_name :book
144
- xml_reader :isbn, :from => :attr
145
- xml_reader :title
146
- xml_reader :description
147
- xml_reader :contributions, :as => [Contributor], :from => 'contributor', :in => "contributions"
148
- end
149
-
150
- class BookWithContributors
151
- include ROXML
152
-
153
- xml_name :book
154
- xml_reader :isbn, :from => :attr
155
- xml_reader :title
156
- xml_reader :description
157
- xml_reader :contributors, :as => [Contributor]
158
- end
159
-
160
- class WriteableBookWithContributors
161
- include ROXML
162
-
163
- xml_name :book
164
- xml_accessor :isbn, :from => :attr
165
- xml_accessor :title
166
- xml_accessor :description
167
- xml_accessor :contributors, :as => [Contributor]
168
- end
169
-
170
- class NamelessBook
171
- include ROXML
172
-
173
- xml_reader :isbn, :from => :attr
174
- xml_reader :title
175
- xml_reader :description
176
- xml_reader :contributors, :as => [Contributor]
177
- end
178
-
179
- class Publisher
180
- include ROXML
181
-
182
- xml_reader :name
183
- end
184
-
185
- class BookWithPublisher
186
- include ROXML
187
-
188
- xml_reader :book
189
- xml_reader :isbn, :from => :attr
190
- xml_reader :title
191
- xml_reader :description
192
- xml_reader :publisher, :as => Publisher
193
- end
194
-
195
- class BookPair
196
- include ROXML
197
-
198
- xml_reader :isbn, :from => :attr
199
- xml_reader :title
200
- xml_reader :description
201
- xml_reader :author
202
- xml_reader :book, :as => Book
203
- end
204
-
205
- class Library
206
- include ROXML
207
-
208
- xml_reader :name
209
- xml_reader :books, :as => [BookWithContributions]
210
- end
211
-
212
- class UppercaseLibrary
213
- include ROXML
214
-
215
- xml_name :library
216
- xml_reader :name, :from => 'NAME'
217
- xml_reader :books, :as => [BookWithContributions], :from => 'BOOK'
218
- end
219
-
220
- class LibraryWithBooksOfUnderivableName
221
- include ROXML
222
-
223
- xml_accessor :name
224
- xml_reader :novels, :as => [NamelessBook]
225
- end
226
-
227
- class NodeWithNameConflicts
228
- include ROXML
229
-
230
- xml_name :node
231
- xml_reader :content
232
- xml_reader :name
233
- end
234
-
235
- class NodeWithAttrNameConflicts
236
- include ROXML
237
-
238
- xml_name :node
239
- xml_reader :content, :from => '@content'
240
- xml_reader :name, :from => '@name'
241
- end
242
-
243
- class Person
244
- include ROXML
245
-
246
- xml_accessor :age, :from => :attr, :else => 21
247
- xml_accessor :name, :from => :content, :else => 'Unknown'
248
-
249
- def self.blank
250
- new.tap do |instance|
251
- instance.age = 21
252
- instance.name = 'Unknown'
253
- end
254
- end
255
- end
256
-
257
- class PersonWithMother
258
- include ROXML
259
-
260
- xml_name :person
261
- xml_reader :name
262
- xml_reader :mother, :as => PersonWithMother, :from => 'mother'
263
- end
264
-
265
- class PersonWithGuardedMother
266
- include ROXML
267
-
268
- xml_name :person
269
- xml_reader :name
270
- xml_reader :mother, :as => PersonWithGuardedMother, :from => :person, :in => :mother
271
- end
272
-
273
- class PersonWithMotherOrMissing
274
- include ROXML
275
-
276
- xml_reader :age, :from => :attr, :else => 21
277
- xml_reader :name, :else => 'Anonymous'
278
- xml_reader :mother,:as => PersonWithMotherOrMissing, :else => Person.blank
279
- end