dozuki 0.0.1 → 0.0.3

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.
@@ -2,28 +2,31 @@ require 'spec_helper'
2
2
 
3
3
  module Dozuki
4
4
  describe XML do
5
-
6
5
  describe "parse" do
7
- let(:string) {"<lall><some xml='true' /></lall>"}
6
+
7
+ let(:args){["xml", :other, :args]}
8
8
  let(:nokogiri_node) {mock "nokogiri node"}
9
9
  let(:dozuki_xml_node) {mock "dozuki xml node"}
10
+
10
11
  before(:each) do
11
12
  Nokogiri::XML.stub(:parse).and_return(nokogiri_node)
12
- XML::Node.stub(:new).and_return(dozuki_xml_node)
13
+ Node.stub(:new).and_return(dozuki_xml_node)
13
14
  end
14
- subject{XML.parse(string)}
15
+
16
+ subject{XML.parse(*args)}
17
+
15
18
  it "should parse the xml using nokogiri" do
16
- Nokogiri::XML.should_receive(:parse).with(string)
19
+ Nokogiri::XML.should_receive(:parse).with(*args).and_return(nokogiri_node)
17
20
  subject
18
21
  end
22
+
19
23
  it "should create a new Node with the nokogiri doc" do
20
- XML::Node.should_receive(:new).with(nokogiri_node)
24
+ Node.should_receive(:new).with(nokogiri_node).and_return(dozuki_xml_node)
21
25
  subject
22
26
  end
23
- it "should return the new node" do
24
- subject.should == dozuki_xml_node
25
- end
27
+
28
+ it {should == dozuki_xml_node}
29
+
26
30
  end
27
-
28
31
  end
29
- end
32
+ end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dozuki
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 1
9
- version: 0.0.1
4
+ prerelease:
5
+ version: 0.0.3
10
6
  platform: ruby
11
7
  authors:
12
8
  - James Almond
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-12-31 00:00:00 +00:00
13
+ date: 2011-04-21 00:00:00 +01:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -25,8 +21,6 @@ dependencies:
25
21
  requirements:
26
22
  - - ">="
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
24
  version: "0"
31
25
  type: :runtime
32
26
  version_requirements: *id001
@@ -38,8 +32,6 @@ dependencies:
38
32
  requirements:
39
33
  - - ">="
40
34
  - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
35
  version: "0"
44
36
  type: :development
45
37
  version_requirements: *id002
@@ -51,8 +43,6 @@ dependencies:
51
43
  requirements:
52
44
  - - ">="
53
45
  - !ruby/object:Gem::Version
54
- segments:
55
- - 0
56
46
  version: "0"
57
47
  type: :development
58
48
  version_requirements: *id003
@@ -64,8 +54,6 @@ dependencies:
64
54
  requirements:
65
55
  - - ">="
66
56
  - !ruby/object:Gem::Version
67
- segments:
68
- - 0
69
57
  version: "0"
70
58
  type: :development
71
59
  version_requirements: *id004
@@ -77,11 +65,20 @@ dependencies:
77
65
  requirements:
78
66
  - - ">="
79
67
  - !ruby/object:Gem::Version
80
- segments:
81
- - 0
82
68
  version: "0"
83
69
  type: :development
84
70
  version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: rake
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ type: :development
81
+ version_requirements: *id006
85
82
  description: A simple way of extracting various elements from an XML document using XPaths
86
83
  email:
87
84
  - james@jamesalmond.com
@@ -95,9 +92,10 @@ files:
95
92
  - .autotest
96
93
  - .gitignore
97
94
  - .rspec
95
+ - CI
98
96
  - Gemfile
99
97
  - Gemfile.lock
100
- - README.rdoc
98
+ - README.markdown
101
99
  - Rakefile
102
100
  - dozuki.gemspec
103
101
  - features/each_accessor.feature
@@ -105,19 +103,22 @@ files:
105
103
  - features/float_accessor.feature
106
104
  - features/get_accessor.feature
107
105
  - features/int_accessor.feature
106
+ - features/steps/collection_steps.rb
107
+ - features/steps/error_steps.rb
108
+ - features/steps/format_steps.rb
108
109
  - features/steps/xml_steps.rb
109
110
  - features/string_accessor.feature
110
111
  - features/support/env.rb
111
112
  - lib/dozuki.rb
113
+ - lib/dozuki/exceptions.rb
114
+ - lib/dozuki/node.rb
115
+ - lib/dozuki/node_collection.rb
116
+ - lib/dozuki/parsers.rb
112
117
  - lib/dozuki/version.rb
113
118
  - lib/dozuki/xml.rb
114
- - lib/dozuki/xml/exceptions.rb
115
- - lib/dozuki/xml/node.rb
116
- - lib/dozuki/xml/node_collection.rb
117
- - lib/dozuki/xml/parser.rb
118
- - spec/dozuki/xml/node_collection_spec.rb
119
- - spec/dozuki/xml/node_spec.rb
120
- - spec/dozuki/xml/parser_spec.rb
119
+ - spec/dozuki/node_collection_spec.rb
120
+ - spec/dozuki/node_spec.rb
121
+ - spec/dozuki/parsers_spec.rb
121
122
  - spec/dozuki/xml_spec.rb
122
123
  - spec/spec_helper.rb
123
124
  has_rdoc: true
@@ -134,21 +135,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
135
  requirements:
135
136
  - - ">="
136
137
  - !ruby/object:Gem::Version
137
- segments:
138
- - 0
139
138
  version: "0"
140
139
  required_rubygems_version: !ruby/object:Gem::Requirement
141
140
  none: false
142
141
  requirements:
143
142
  - - ">="
144
143
  - !ruby/object:Gem::Version
145
- segments:
146
- - 0
147
144
  version: "0"
148
145
  requirements: []
149
146
 
150
147
  rubyforge_project: dozuki
151
- rubygems_version: 1.3.7
148
+ rubygems_version: 1.6.2
152
149
  signing_key:
153
150
  specification_version: 3
154
151
  summary: An XPath syntactic sugar wrapper for Nokogiri
@@ -159,11 +156,14 @@ test_files:
159
156
  - features/float_accessor.feature
160
157
  - features/get_accessor.feature
161
158
  - features/int_accessor.feature
159
+ - features/steps/collection_steps.rb
160
+ - features/steps/error_steps.rb
161
+ - features/steps/format_steps.rb
162
162
  - features/steps/xml_steps.rb
163
163
  - features/string_accessor.feature
164
164
  - features/support/env.rb
165
- - spec/dozuki/xml/node_collection_spec.rb
166
- - spec/dozuki/xml/node_spec.rb
167
- - spec/dozuki/xml/parser_spec.rb
165
+ - spec/dozuki/node_collection_spec.rb
166
+ - spec/dozuki/node_spec.rb
167
+ - spec/dozuki/parsers_spec.rb
168
168
  - spec/dozuki/xml_spec.rb
169
169
  - spec/spec_helper.rb
@@ -1,27 +0,0 @@
1
- module Dozuki
2
- module XML
3
-
4
- class NotFound < StandardError
5
- attr_accessor :xpath, :node
6
-
7
- def initialize(msg=nil, opts={})
8
- super msg
9
- self.xpath = opts[:xpath]
10
- self.node = opts[:node]
11
- end
12
-
13
- end
14
-
15
- class InvalidFormat < StandardError
16
- attr_accessor :format, :node, :value
17
-
18
- def initialize(msg=nil, opts={})
19
- super msg
20
- self.format = opts[:format]
21
- self.node = opts[:node]
22
- self.value = opts[:value]
23
- end
24
- end
25
-
26
- end
27
- end
@@ -1,54 +0,0 @@
1
- module Dozuki
2
- module XML
3
- class Node
4
- attr_accessor :nokogiri_node
5
-
6
- def initialize(nokogiri_node)
7
- self.nokogiri_node = nokogiri_node
8
- end
9
-
10
- def method_missing(method, *args, &blk)
11
- nokogiri_node.send(method, *args, &blk)
12
- end
13
-
14
- def respond_to?(method)
15
- nokogiri_node.respond_to?(method) ? true : super
16
- end
17
-
18
- def each(xpath, &blk)
19
- collection = NodeCollection.new(nokogiri_node.xpath(xpath))
20
- block_given? ? collection.as_node(&blk) : collection
21
- end
22
-
23
- def string(xpath)
24
- Parser.to_string(get_first_node(xpath))
25
- end
26
-
27
- def int(xpath)
28
- Parser.to_int(get_first_node(xpath))
29
- end
30
-
31
- def float(xpath)
32
- Parser.to_float(get_first_node(xpath))
33
- end
34
-
35
- def get(xpath)
36
- node = Node.new(get_first_node(xpath))
37
- yield node if block_given?
38
- node
39
- end
40
-
41
- def exists?(xpath)
42
- !nokogiri_node.xpath(xpath).empty?
43
- end
44
-
45
- private
46
- def get_first_node(xpath)
47
- node = nokogiri_node.xpath(xpath)
48
- raise NotFound.new("Node not found", :xpath => xpath, :node => nokogiri_node) if node.empty?
49
- node.first
50
- end
51
-
52
- end
53
- end
54
- end
@@ -1,27 +0,0 @@
1
- module Dozuki
2
- module XML
3
- class NodeCollection
4
- attr_accessor :collection
5
-
6
- def initialize(collection)
7
- self.collection = collection
8
- end
9
-
10
- def as_node(&blk)
11
- collection.each{|item| blk.call(Node.new(item))}
12
- end
13
-
14
- def as_string(&blk)
15
- collection.each{|item| blk.call(Parser.to_string(item))}
16
- end
17
-
18
- def as_int(&blk)
19
- collection.each{|item| blk.call(Parser.to_int(item))}
20
- end
21
-
22
- def as_float(&blk)
23
- collection.each{|item| blk.call(Parser.to_float(item))}
24
- end
25
- end
26
- end
27
- end
@@ -1,23 +0,0 @@
1
- module Dozuki
2
- module XML
3
- module Parser
4
-
5
- def self.to_string(node)
6
- node.text.strip
7
- end
8
-
9
- def self.to_int(node)
10
- string = to_string(node)
11
- raise InvalidFormat.new("Parsing error", :node => node, :value => string, :format => "int") unless string =~ /^-?[0-9]+$/
12
- string.to_i
13
- end
14
-
15
- def self.to_float(node)
16
- string = to_string(node)
17
- raise InvalidFormat.new("Parsing error", :node => node, :value => string, :format => "float") unless string =~ /^-?[0-9]+(\.[0-9]+)?$/
18
- string.to_f
19
- end
20
-
21
- end
22
- end
23
- end
@@ -1,117 +0,0 @@
1
- require 'spec_helper'
2
- module Dozuki
3
- module XML
4
- describe NodeCollection do
5
-
6
- describe "as_node" do
7
- let(:collection){mock "some_nodes"}
8
- let(:blk){Proc.new{}}
9
- let(:node_collection){NodeCollection.new(collection)}
10
- let(:collection_item){mock "collection item"}
11
- let(:new_node){mock "new node"}
12
- before(:each) do
13
- collection.stub(:each).and_yield(collection_item)
14
- Node.stub(:new).and_return(new_node)
15
- end
16
-
17
- subject{node_collection.as_node(&blk)}
18
-
19
- it "should iterate through the collection" do
20
- collection.should_receive(:each)
21
- subject
22
- end
23
- it "should create a new Node with the yielded collection item" do
24
- Node.should_receive(:new).with(collection_item)
25
- subject
26
- end
27
- it "should call the bloc with the node" do
28
- blk.should_receive(:call).with(new_node)
29
- subject
30
- end
31
- end
32
-
33
- describe "as_string" do
34
- let(:collection){mock "some_nodes"}
35
- let(:blk){Proc.new{}}
36
- let(:node_collection){NodeCollection.new(collection)}
37
- let(:collection_item){mock "collection item"}
38
- let(:string){"string"}
39
- before(:each) do
40
- collection.stub(:each).and_yield(collection_item)
41
- Parser.stub(:to_string).and_return(string)
42
- end
43
-
44
- subject{node_collection.as_string(&blk)}
45
-
46
- it "should iterate through the collection" do
47
- collection.should_receive(:each)
48
- subject
49
- end
50
- it "should create a new Node with the yielded collection item" do
51
- Parser.should_receive(:to_string).with(collection_item)
52
- subject
53
- end
54
- it "should call the bloc with the node" do
55
- blk.should_receive(:call).with("string")
56
- subject
57
- end
58
- end
59
-
60
- describe "as_int" do
61
- let(:collection){mock "some_nodes"}
62
- let(:blk){Proc.new{}}
63
- let(:node_collection){NodeCollection.new(collection)}
64
- let(:collection_item){mock "collection item"}
65
- let(:int){39}
66
- before(:each) do
67
- collection.stub(:each).and_yield(collection_item)
68
- Parser.stub(:to_int).and_return(int)
69
- end
70
-
71
- subject{node_collection.as_int(&blk)}
72
-
73
- it "should iterate through the collection" do
74
- collection.should_receive(:each)
75
- subject
76
- end
77
- it "should create a new Node with the yielded collection item" do
78
- Parser.should_receive(:to_int).with(collection_item)
79
- subject
80
- end
81
- it "should call the bloc with the node" do
82
- blk.should_receive(:call).with(int)
83
- subject
84
- end
85
- end
86
-
87
- describe "as_float" do
88
- let(:collection){mock "some_nodes"}
89
- let(:blk){Proc.new{}}
90
- let(:node_collection){NodeCollection.new(collection)}
91
- let(:collection_item){mock "collection item"}
92
- let(:float){39.50}
93
- before(:each) do
94
- collection.stub(:each).and_yield(collection_item)
95
- Parser.stub(:to_float).and_return(float)
96
- end
97
-
98
- subject{node_collection.as_float(&blk)}
99
-
100
- it "should iterate through the collection" do
101
- collection.should_receive(:each)
102
- subject
103
- end
104
- it "should create a new Node with the yielded collection item" do
105
- Parser.should_receive(:to_float).with(collection_item)
106
- subject
107
- end
108
- it "should call the bloc with the node" do
109
- blk.should_receive(:call).with(float)
110
- subject
111
- end
112
- end
113
-
114
-
115
- end
116
- end
117
- end