mida 0.1.2 → 0.1.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.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,12 @@
1
+ == 0.1.3 (18th April 2011)
2
+ * Ensure itemprops are parsed properly if containing non-microdata elements
3
+ * Support itemprops nested within other itemprops
4
+
5
+ == 0.1.2 (14th April 2011)
6
+ * Add version for rspec dependency
7
+
8
+ == 0.1.1 (12th April 2011)
9
+ * Improve gemspec description
10
+
11
+ == 0.1.0 (12th April 2011)
12
+ * Initial Release
data/Rakefile CHANGED
@@ -6,14 +6,14 @@ spec = Gem::Specification.new do |s|
6
6
  s.name = "mida"
7
7
  s.summary = "A Microdata parser/extractor library"
8
8
  s.description = "A Microdata parser and extractor library, based on the latest published version of the Microdata Specification, dated 5th April 2011."
9
- s.version = "0.1.2"
9
+ s.version = "0.1.3"
10
10
  s.author = "Lawrence Woodman"
11
11
  s.email = "lwoodman@vlifesystems.com"
12
12
  s.homepage = %q{http://github.com/LawrenceWoodman/mida}
13
13
  s.platform = Gem::Platform::RUBY
14
14
  s.required_ruby_version = '>=1.9'
15
15
  s.files = Dir['lib/**/*.rb'] + Dir['spec/**/*.rb'] + Dir['*.rdoc'] + Dir['Rakefile']
16
- s.extra_rdoc_files = ['README.rdoc', 'LICENSE.rdoc']
16
+ s.extra_rdoc_files = ['README.rdoc', 'LICENSE.rdoc', 'CHANGELOG.rdoc']
17
17
  s.rdoc_options << '--main' << 'README.rdoc'
18
18
  s.add_dependency('nokogiri')
19
19
  s.add_development_dependency('rspec', '>= 2.0' )
data/lib/mida/item.rb CHANGED
@@ -81,12 +81,11 @@ module Mida
81
81
 
82
82
  def traverse_elements(elements)
83
83
  elements.each do |element|
84
+ itemscope = element.attribute('itemscope')
85
+ itemprop = element.attribute('itemprop')
84
86
  internal_elements = extract_elements(element)
85
- if internal_elements.empty? || element.attribute('itemscope')
86
- add_itemprop(element)
87
- else
88
- traverse_elements(internal_elements)
89
- end
87
+ add_itemprop(element) if itemscope || itemprop
88
+ traverse_elements(internal_elements) if internal_elements && !itemscope
90
89
  end
91
90
  end
92
91
 
data/lib/mida/property.rb CHANGED
@@ -11,11 +11,9 @@ module Mida
11
11
  # [element] The itemprop element to be parsed
12
12
  # [page_url] The url of the page, including the filename, used to form absolute urls
13
13
  def self.parse(element, page_url=nil)
14
- hash = {}
15
- extract_property_names(element).each do |name|
16
- hash[name] = extract_property(element, page_url)
14
+ extract_property_names(element).each_with_object({}) do |name, memo|
15
+ memo[name] = extract_property(element, page_url)
17
16
  end
18
- hash
19
17
  end
20
18
 
21
19
  NON_TEXTCONTENT_ELEMENTS = {
data/spec/item_spec.rb CHANGED
@@ -136,6 +136,82 @@ describe Mida::Item, 'when initialized with an itemscope containing itemprops su
136
136
 
137
137
  end
138
138
 
139
+ describe Mida::Item, "when initialized with an itemscope containing itemprops
140
+ who's inner text is surrounded by non-microdata elements" do
141
+ before do
142
+ html = '<div itemscope><span itemprop="reviewer">Lorry <em>Woodman</em></span></div>'
143
+ doc = Nokogiri(html)
144
+ itemscope = doc.search('./*').first
145
+ @item = Mida::Item.new(itemscope)
146
+ end
147
+
148
+ it '#type should return the correct type' do
149
+ @item.type.should == nil
150
+ end
151
+
152
+ it '#id should return the correct id' do
153
+ @item.id.should == nil
154
+ end
155
+
156
+ it '#properties should return the correct name/value pairs' do
157
+ @item.properties.should == {
158
+ 'reviewer' => ['Lorry Woodman']
159
+ }
160
+ end
161
+
162
+ it '#to_h should return the correct type and properties' do
163
+ @item.to_h.should == {
164
+ type: nil,
165
+ id: nil,
166
+ properties: {
167
+ 'reviewer' => ['Lorry Woodman']
168
+ }
169
+ }
170
+ end
171
+
172
+ end
173
+
174
+ describe Mida::Item, "when initialized with an itemscope containing an itemprop
175
+ nested within another itemprop" do
176
+ before do
177
+ html = '
178
+ <div itemscope>
179
+ <span itemprop="description">The animal is a <span itemprop="colour">green</span> parrot.</span>
180
+ </div>
181
+ '
182
+ doc = Nokogiri(html)
183
+ itemscope = doc.search('./*').first
184
+ @item = Mida::Item.new(itemscope)
185
+ end
186
+
187
+ it '#type should return the correct type' do
188
+ @item.type.should == nil
189
+ end
190
+
191
+ it '#id should return the correct id' do
192
+ @item.id.should == nil
193
+ end
194
+
195
+ it '#properties should return the correct name/value pairs' do
196
+ @item.properties.should == {
197
+ 'description' => ['The animal is a green parrot.'],
198
+ 'colour' => ['green']
199
+ }
200
+ end
201
+
202
+ it '#to_h should return the correct type and properties' do
203
+ @item.to_h.should == {
204
+ type: nil,
205
+ id: nil,
206
+ properties: {
207
+ 'description' => ['The animal is a green parrot.'],
208
+ 'colour' => ['green']
209
+ }
210
+ }
211
+ end
212
+
213
+ end
214
+
139
215
  describe Mida::Item, 'when initialized with an itemscope containing itemprops with the same name' do
140
216
  before do
141
217
  # Lemon Sorbet flavour
@@ -22,6 +22,19 @@ describe Mida::Property, 'when parsing an element with one itemprop name' do
22
22
  end
23
23
  end
24
24
 
25
+ describe Mida::Property, "when parsing an element who's inner text contains\
26
+ non microdata elements" do
27
+ before do
28
+ html = '<span itemprop="reviewer">Lorry <em>Woodman</em></span>'
29
+ doc = Nokogiri(html)
30
+ @itemprop = doc.search('./*').first
31
+ end
32
+
33
+ it '#parse should return a Hash with the correct name/value pair' do
34
+ Mida::Property.parse(@itemprop).should == {'reviewer' => 'Lorry Woodman'}
35
+ end
36
+ end
37
+
25
38
  describe Mida::Property, 'when parsing an itemscope element that has a relative url' do
26
39
  before do
27
40
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mida
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.1.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Lawrence Woodman
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-15 00:00:00 Z
13
+ date: 2011-04-18 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -43,6 +43,7 @@ extensions: []
43
43
  extra_rdoc_files:
44
44
  - README.rdoc
45
45
  - LICENSE.rdoc
46
+ - CHANGELOG.rdoc
46
47
  files:
47
48
  - lib/mida.rb
48
49
  - lib/mida/property.rb
@@ -53,6 +54,7 @@ files:
53
54
  - spec/item_spec.rb
54
55
  - spec/spec_helper.rb
55
56
  - TODO.rdoc
57
+ - CHANGELOG.rdoc
56
58
  - README.rdoc
57
59
  - LICENSE.rdoc
58
60
  - Rakefile