microdata 0.0.2 → 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.
@@ -5,4 +5,21 @@
5
5
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
6
6
  require 'microdata'
7
7
 
8
- puts Microdata.to_json(ARGV[0])
8
+ location = ARGV[0]
9
+ content = open(location)
10
+ document = Microdata::Document.new(content, location)
11
+ items = document.extract_items
12
+
13
+ if items.empty? || items.nil?
14
+ puts "No Microdata items found."
15
+ itemprops = document.doc.search('//*[@itemprop]')
16
+ if !itemprops.empty?
17
+ puts "There are some itemprops, which means no top level items with an itemscope have been found."
18
+ end
19
+ else
20
+ hash = {}
21
+ hash[:items] = items.map do |item|
22
+ item.to_hash
23
+ end
24
+ puts JSON.pretty_generate(hash)
25
+ end
@@ -1,7 +1,7 @@
1
1
  module Microdata
2
2
  class Document
3
3
 
4
- attr_reader :items
4
+ attr_reader :items, :doc
5
5
 
6
6
  def initialize(content, page_url=nil)
7
7
  @doc = Nokogiri::HTML(content)
@@ -1,3 +1,3 @@
1
1
  module Microdata
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,22 @@
1
+ <!doctype html>
2
+ <html>
3
+ <!-- shameless -->
4
+ <head>
5
+ <title>Jason Ronallo</title>
6
+ </head>
7
+
8
+ <body>
9
+ <span itemtype="http://schema.org/Person"
10
+ itemid="http://ronallo.com#me">
11
+ <a itemprop="url" href="http://twitter.com/ronallo">
12
+ <span itemprop="name">Jason Ronallo</span>
13
+ </a> is the
14
+ <span itemprop="jobTitle">Associate Head of Digital Library Initiatives</span> at
15
+ <span itemprop="affiliation" itemtype="http://schema.org/Library" itemid="http://lib.ncsu.edu">
16
+ <span itemprop="name">
17
+ <a itemprop="url" href="http://www.lib.ncsu.edu">NCSU Libraries</a>
18
+ </span>
19
+ </span>.
20
+ </span>
21
+ </body>
22
+ </html>
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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -81,6 +81,7 @@ files:
81
81
  - microdata.gemspec
82
82
  - test/data/example.html
83
83
  - test/data/example_itemref.html
84
+ - test/data/example_with_no_itemscope.html
84
85
  - test/test_helper.rb
85
86
  - test/test_itemref.rb
86
87
  - test/test_parse.rb
@@ -112,6 +113,7 @@ summary: Ruby library for extracting HTML5 Microdata
112
113
  test_files:
113
114
  - test/data/example.html
114
115
  - test/data/example_itemref.html
116
+ - test/data/example_with_no_itemscope.html
115
117
  - test/test_helper.rb
116
118
  - test/test_itemref.rb
117
119
  - test/test_parse.rb