saxomattic 0.0.1 → 0.0.2

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.
@@ -1,3 +1,3 @@
1
1
  module Saxomattic
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/saxomattic.rb CHANGED
@@ -49,7 +49,8 @@ module Saxomattic
49
49
  module ClassMethods
50
50
  def attribute(*args)
51
51
  options = args.extract_options!
52
- field = args.first
52
+ sax_field = args.first
53
+ attr_field = options[:as] || sax_field
53
54
 
54
55
  # If you want to setup a default set of elements, you can!
55
56
  # :default => [ true, false, false, true ]
@@ -57,28 +58,28 @@ module Saxomattic
57
58
  options.merge!(:default => [])
58
59
  end
59
60
 
60
- _active_attr_attribute(field, _active_attr_attributes(options.dup))
61
+ _active_attr_attribute(attr_field, _active_attr_attributes(options.dup))
61
62
 
62
63
  case
63
64
  when options[:ancestor] then
64
- _sax_machine_ancestor(field, _sax_machine_attributes(options.dup))
65
+ _sax_machine_ancestor(sax_field, _sax_machine_attributes(options.dup))
65
66
  when options[:attribute] then
66
- _sax_machine_attribute(field, _sax_machine_attributes(options.dup))
67
+ _sax_machine_attribute(sax_field, _sax_machine_attributes(options.dup))
67
68
  when options[:elements] then
68
- _sax_machine_elements(field, _sax_machine_attributes(options.dup))
69
+ _sax_machine_elements(sax_field, _sax_machine_attributes(options.dup))
69
70
  when options[:value] then
70
- _sax_machine_value(field, _sax_machine_attributes(options.dup))
71
+ _sax_machine_value(sax_field, _sax_machine_attributes(options.dup))
71
72
  else # Default state is an element
72
- _sax_machine_element(field, _sax_machine_attributes(options.dup))
73
+ _sax_machine_element(sax_field, _sax_machine_attributes(options.dup))
73
74
  end
74
75
  end
75
76
 
76
77
  def _active_attr_attributes(options_hash = {})
77
- options_hash.slice!(::Saxomattic::ACTIVE_ATTR_ATTRIBUTES)
78
+ options_hash.slice(*::Saxomattic::ACTIVE_ATTR_ATTRIBUTES)
78
79
  end
79
80
 
80
81
  def _sax_machine_attributes(options_hash = {})
81
- options_hash.slice!(::Saxomattic::SAX_MACHINE_ATTRIBUTES)
82
+ options_hash.slice(*::Saxomattic::SAX_MACHINE_ATTRIBUTES)
82
83
  end
83
84
  end
84
85
 
@@ -16,6 +16,12 @@ class SaxTesterEmbedded
16
16
  attribute :embedception, :class => SaxTesterEmbedception
17
17
  end
18
18
 
19
+ class SaxTesterChild
20
+ include Saxomattic
21
+
22
+ attribute :name
23
+ end
24
+
19
25
  class SaxTesterSomething
20
26
  include Saxomattic
21
27
 
@@ -25,6 +31,8 @@ class SaxTesterSomething
25
31
  attribute :date, :type => Date
26
32
  attribute :datetime, :type => DateTime
27
33
  attribute :embedded, :elements => true, :class => SaxTesterEmbedded
34
+ attribute :child, :as => :children, :elements => true, :class => SaxTesterChild
35
+ attribute :CAPITALIZATION, :as => :capitalization
28
36
  end
29
37
 
30
38
  describe ::Saxomattic do
@@ -45,8 +53,17 @@ describe ::Saxomattic do
45
53
  <embed>#{embedded_message}</embed>
46
54
  <embedception type="#{embedception_type}">#{embedception_value}</embedception>
47
55
  </embedded>
56
+ <parent>
57
+ <child>
58
+ <name>John</name>
59
+ </child>
60
+ <child>
61
+ <name>Paul</name>
62
+ </child>
63
+ </parent>
48
64
  <date>#{Date.today}</date>
49
65
  <foo>2</foo>
66
+ <CAPITALIZATION>cap</CAPITALIZATION>
50
67
  </test>
51
68
  XML
52
69
  }
@@ -82,6 +99,12 @@ describe ::Saxomattic do
82
99
  subject.embedded.first.embedception.value.should eq(embedception_value)
83
100
  subject.embedded.first.embedception.not_even_used?.should be_false
84
101
  end
102
+
103
+ it "extracts multiple children from a parent element" do
104
+ subject.children.size.should eq 2
105
+ subject.children.first.name.should eq "John"
106
+ subject.children.last.name.should eq "Paul"
107
+ end
85
108
  end
86
109
 
87
110
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saxomattic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-13 00:00:00.000000000 Z
12
+ date: 2013-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: active_attr
@@ -155,7 +155,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  segments:
157
157
  - 0
158
- hash: -4328511533199913678
158
+ hash: -1921715027979040477
159
159
  required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  version: '0'
165
165
  segments:
166
166
  - 0
167
- hash: -4328511533199913678
167
+ hash: -1921715027979040477
168
168
  requirements: []
169
169
  rubyforge_project:
170
170
  rubygems_version: 1.8.24