test/mocks/mocks.rb in Empact-roxml-2.1 vs test/mocks/mocks.rb in Empact-roxml-2.2
- old
+ new
@@ -1,25 +1,74 @@
require "lib/roxml"
+class Muffins
+ include ROXML
+
+ xml_reader(:count, :from => 'bakers_dozens') {|val| val.to_i * 13 }
+end
+
+class MuffinsWithStackedBlocks
+ include ROXML
+
+ xml_reader(:count, :from => 'bakers_dozens', :as => Integer) {|val| val * 13 }
+end
+
+class Numerology
+ include ROXML
+
+ xml_reader :predictions, {:attrs => ['number', 'meaning']} do |k, v|
+ [Integer(k), v]
+ end
+end
+
+class Contributor
+ include ROXML
+
+ xml_reader :role, :attr
+ xml_reader :name
+end
+
+class WriteableContributor
+ include ROXML
+
+ xml_accessor :role, :attr
+ xml_accessor :name
+end
+
class Book
include ROXML
xml_accessor :isbn, :attr => 'ISBN'
xml_reader :title
xml_reader :description, :as => :cdata
xml_reader :author
- xml_accessor :pages, :text => 'pagecount' do |val|
- Integer(val)
- end
+ xml_accessor :pages, :text => 'pagecount', :as => Integer
end
+class BookWithRequired
+ include ROXML
+
+ xml_accessor :isbn, :attr => 'ISBN', :required => true
+ xml_reader :title, :required => true
+ xml_reader :contributors, [Contributor], :in => 'contributor_array', :required => true
+ xml_reader :contributor_hash, {:attrs => ['role', 'name']},
+ :from => 'contributor', :in => 'contributor_hash', :required => true
+end
+
class BookWithAttrFrom
include ROXML
xml_accessor :isbn, :attr, :from => 'ISBN'
end
+class BookWithWrappedAttr
+ include ROXML
+
+ xml_name :book
+ xml_accessor :isbn, :attr => 'ISBN', :in => 'ids'
+end
+
class Measurement
include ROXML
xml_reader :units, :attr
xml_reader :value, :content
@@ -78,17 +127,10 @@
xml_reader :title
xml_reader :description, :as => :cdata
xml_reader :author, Author
end
-class Contributor
- include ROXML
-
- xml_reader :role, :attr
- xml_reader :name
-end
-
class BookWithContributions
include ROXML
xml_name :book
xml_reader :isbn, :attr
@@ -105,10 +147,20 @@
xml_reader :title
xml_reader :description
xml_reader :contributors, Contributor, :as => :array
end
+class WriteableBookWithContributors
+ include ROXML
+
+ xml_name :book
+ xml_accessor :isbn, :attr
+ xml_accessor :title
+ xml_accessor :description
+ xml_accessor :contributors, Contributor, :as => :array
+end
+
class NamelessBook
include ROXML
xml_reader :isbn, :attr
xml_reader :title
@@ -207,6 +259,6 @@
include ROXML
xml_reader :age, :attr, :else => 21
xml_reader :name, :else => 'Anonymous'
xml_reader :mother, PersonWithMotherOrMissing, :else => Person.new
-end
\ No newline at end of file
+end