microformat 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.
data/README.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  Reads Microformats from HTML documents
4
4
 
5
+ [![Build Status][2]][1] [![Code Climate][3]][4]
6
+
7
+ [1]: http://travis-ci.org/platformq/microformat
8
+ [2]: https://secure.travis-ci.org/platformq/microformat.png?branch=master
9
+ [3]: https://codeclimate.com/badge.png
10
+ [4]: https://codeclimate.com/github/platformq/microformat
11
+
5
12
  ## Installation
6
13
 
7
14
  Add this line to your application's Gemfile:
@@ -34,45 +41,11 @@ require "nokogiri"
34
41
 
35
42
  html = "<html>...</html>"
36
43
  doc = Nokogiri::HTML(html)
37
- element = doc.css(".hreview")
44
+ element = doc.css("body")
38
45
  Microformat.parse(element)
39
46
  # => Microformat::Collection
40
47
  ```
41
48
 
42
- Collections act as standard Ruby arrays, however they provide additional filtering methods:
43
-
44
- ```ruby
45
- collection = Microformat.parse(element)
46
- # => Microformat::Collection (of all microformat objects)
47
- collection.filter(Microformat::Review, Microformat::ReviewAggregate)
48
- # => Microformat::Collection (of only hreviews and hreview-aggregates)
49
- ```
50
-
51
- You can also improve performance by passing a set of formats to the initial parse:
52
-
53
- ```ruby
54
- formats = [Microformat::Review, Microformat::Card]
55
- Microformat.parse(element, filter: formats)
56
- # => Microformat::Collection (of only hreviews and hcards)
57
- ```
58
-
59
- You can specify a limit (should you only want the first or a few objects)
60
-
61
- ```ruby
62
- Microformat.parse(element, limit: 3)
63
- # => Microformat::Collection (of max size 3)
64
- ```
65
-
66
- You can also parse a Nokogiri element to return an object of the first found exact Microformat:
67
-
68
- ```ruby
69
- html = "<html>...</html>"
70
- doc = Nokogiri::HTML(html)
71
- element = doc.css(".hcard")
72
- Microformat::Card.parse(element)
73
- # => Microformat::Card instance
74
- ```
75
-
76
49
  ## Contributing
77
50
 
78
51
  1. Fork it
@@ -42,7 +42,13 @@ module Microformat
42
42
 
43
43
  private
44
44
  def elements
45
- @elements ||= doc.css(selectors.join(", "))
45
+ @elements ||= [].tap do |elements|
46
+ while doc.css(selectors.join(", ")).length > 0
47
+ node = doc.css(selectors.join(", ")).first
48
+ node.remove
49
+ elements.push node
50
+ end
51
+ end
46
52
  end
47
53
  end
48
54
  end
@@ -1,3 +1,3 @@
1
1
  module Microformat
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -30,6 +30,18 @@ describe Microformat::Parser do
30
30
  </body></html>)
31
31
  end
32
32
 
33
+ let(:nested_review_html) do
34
+ %Q(<html><body>
35
+ <div class="hreview">
36
+ <div class="summary">It's good</div>
37
+ <div class="reviewer">
38
+ <p class="fn">Dave</p>
39
+ <div class="hreview"></div>
40
+ </div>
41
+ </div>
42
+ </body></html>)
43
+ end
44
+
33
45
  context "given a HTML string" do
34
46
  let(:doc) { html }
35
47
 
@@ -79,5 +91,31 @@ describe Microformat::Parser do
79
91
  end
80
92
  end
81
93
  end
94
+
95
+ context "given a HTML document with nested microformats" do
96
+ let(:doc) { Nokogiri::HTML(nested_review_html) }
97
+
98
+ it "should return a collection with one object" do
99
+ expect(subject.size).to eq 1
100
+ end
101
+
102
+ describe "the returned Microformat object" do
103
+ subject do
104
+ Microformat::Parser.parse(doc).first
105
+ end
106
+
107
+ it "should be a Microformat::Review" do
108
+ expect(subject).to be_kind_of(Microformat::Review)
109
+ end
110
+
111
+ it "should return the summary" do
112
+ expect(subject.summary.value).to eq "It's good"
113
+ end
114
+
115
+ it "should return the reviewer's full name" do
116
+ expect(subject.reviewer.fn.value).to eq "Dave"
117
+ end
118
+ end
119
+ end
82
120
  end
83
121
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: microformat
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:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-22 00:00:00.000000000 Z
12
+ date: 2012-11-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -122,15 +122,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
122
  - - ! '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ segments:
126
+ - 0
127
+ hash: -2467505088189709361
125
128
  required_rubygems_version: !ruby/object:Gem::Requirement
126
129
  none: false
127
130
  requirements:
128
131
  - - ! '>='
129
132
  - !ruby/object:Gem::Version
130
133
  version: '0'
134
+ segments:
135
+ - 0
136
+ hash: -2467505088189709361
131
137
  requirements: []
132
138
  rubyforge_project:
133
- rubygems_version: 1.8.23
139
+ rubygems_version: 1.8.24
134
140
  signing_key:
135
141
  specification_version: 3
136
142
  summary: Reads Microformats from HTML documents