microdata 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in microdata.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem 'pry'
8
+ end
@@ -8,6 +8,7 @@ module Microdata
8
8
  @id = extract_itemid
9
9
  @properties = {}
10
10
  @page_url = page_url
11
+ add_itemref_properties(@top_node)
11
12
  parse_elements(extract_elements(@top_node))
12
13
  end
13
14
 
@@ -61,5 +62,18 @@ module Microdata
61
62
  properties.each { |name, value| (@properties[name] ||= []) << value }
62
63
  end
63
64
 
65
+ # Add any properties referred to by 'itemref'
66
+ def add_itemref_properties(element)
67
+ itemref = element.attribute('itemref')
68
+ if itemref
69
+ itemref.value.split(' ').each {|id| parse_elements(find_with_id(id))}
70
+ end
71
+ end
72
+
73
+ # Find an element with a matching id
74
+ def find_with_id(id)
75
+ @top_node.search("//*[@id='#{id}']")
76
+ end
77
+
64
78
  end
65
79
  end
@@ -1,3 +1,3 @@
1
1
  module Microdata
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,16 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>itemref example from Microdata spec</title>
5
+ </head>
6
+
7
+ <body>
8
+ <div itemscope id="amanda" itemref="a b"></div>
9
+ <p id="a">Name: <span itemprop="name">Amanda</span></p>
10
+ <div id="b" itemprop="band" itemscope itemref="c"></div>
11
+ <div id="c">
12
+ <p>Band: <span itemprop="name">Jazz Band</span></p>
13
+ <p>Size: <span itemprop="size">12</span> players</p>
14
+ </div>
15
+ </body>
16
+ </html>
data/test/test_helper.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'test/unit'
2
- require 'microdata'
2
+ require 'microdata'
3
+ require 'pry'
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ class TestItemref < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @items = Microdata.get_items('test/data/example_itemref.html')
7
+ end
8
+
9
+ def test_top_item_name
10
+ assert_equal ['Amanda'], @items.first.properties['name']
11
+ end
12
+
13
+ def test_band_name_and_size
14
+ band = @items.first.properties['band'].first
15
+ assert_equal ['Jazz Band'], band.properties['name']
16
+ assert_equal ['12'], band.properties['size']
17
+ end
18
+
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: microdata
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-03-16 00:00:00.000000000 Z
12
+ date: 2013-03-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -80,7 +80,9 @@ files:
80
80
  - lib/microdata/version.rb
81
81
  - microdata.gemspec
82
82
  - test/data/example.html
83
+ - test/data/example_itemref.html
83
84
  - test/test_helper.rb
85
+ - test/test_itemref.rb
84
86
  - test/test_parse.rb
85
87
  homepage: ''
86
88
  licenses:
@@ -109,6 +111,8 @@ specification_version: 3
109
111
  summary: Ruby library for extracting HTML5 Microdata
110
112
  test_files:
111
113
  - test/data/example.html
114
+ - test/data/example_itemref.html
112
115
  - test/test_helper.rb
116
+ - test/test_itemref.rb
113
117
  - test/test_parse.rb
114
118
  has_rdoc: