hentry_consumer 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/hentry_consumer/element.rb +14 -3
- data/lib/hentry_consumer/h_entry.rb +2 -2
- data/lib/hentry_consumer/h_feed.rb +4 -0
- data/lib/hentry_consumer/version.rb +1 -1
- data/lib/hentry_consumer.rb +1 -0
- data/spec/lib/hentry_consumer/h_entry_spec.rb +2 -2
- data/spec/lib/hentry_consumer/h_feed_spec.rb +13 -1
- data/spec/support/example.html +159 -162
- metadata +2 -2
data/README.md
CHANGED
@@ -1,12 +1,23 @@
|
|
1
1
|
module HentryConsumer
|
2
2
|
class Element
|
3
|
+
attr_accessor :element
|
4
|
+
|
3
5
|
def initialize(microformat)
|
4
|
-
|
6
|
+
@element = microformat
|
7
|
+
parse_elements
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_html
|
11
|
+
@element.to_html
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_xml
|
15
|
+
@element.to_xml
|
5
16
|
end
|
6
17
|
|
7
|
-
def parse_elements
|
18
|
+
def parse_elements
|
8
19
|
FormatClass.each do |letter|
|
9
|
-
|
20
|
+
@element.css(">*[class*=#{letter}-]").each do |a|
|
10
21
|
assign_value(symbolize_class(a["class"]), a.text.gsub('\n', " ").strip)
|
11
22
|
end
|
12
23
|
end
|
@@ -4,9 +4,9 @@ module HentryConsumer
|
|
4
4
|
attr_accessor :name, :categories, :author, :content, :bookmark, :published_at, :summary
|
5
5
|
alias_method :authors, :author
|
6
6
|
|
7
|
-
def parse_elements
|
7
|
+
def parse_elements
|
8
8
|
FormatClass.each do |letter|
|
9
|
-
|
9
|
+
@element.css(">*[class*=#{letter}-]").each do |attrs|
|
10
10
|
attrs["class"].split.each do |klass|
|
11
11
|
parse_element(attrs, klass)
|
12
12
|
end
|
data/lib/hentry_consumer.rb
CHANGED
@@ -7,7 +7,7 @@ describe HentryConsumer::HEntry do
|
|
7
7
|
it "should have an array of entries" do
|
8
8
|
entry.should be_an_instance_of HentryConsumer::HEntry
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
it "has a name" do
|
12
12
|
entry.name.should eq ["Senior Cat Living"]
|
13
13
|
end
|
@@ -57,7 +57,7 @@ describe HentryConsumer::HEntry do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
describe "json" do
|
62
62
|
let(:json) { JSON.parse(entry.to_json) }
|
63
63
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'hentry_consumer'
|
2
2
|
|
3
3
|
describe HentryConsumer::HFeed do
|
4
|
+
let(:feed) { HentryConsumer.parse(File.open("spec/support/example.html")) }
|
4
5
|
|
5
6
|
describe "to json" do
|
6
|
-
let(:feed) { HentryConsumer.parse(File.open("spec/support/example.html")) }
|
7
7
|
let(:json) { JSON.parse(feed.to_json) }
|
8
8
|
|
9
9
|
it { json["items"].first["type"].should include 'h-feed'}
|
@@ -12,4 +12,16 @@ describe HentryConsumer::HFeed do
|
|
12
12
|
it { json["items"].first["properties"]["entries"].first["items"].first["type"].should include "h-entry" }
|
13
13
|
|
14
14
|
end
|
15
|
+
# <article class=\"h-entry\"><h1 class=\"p-name\">Senior Cat Living</h1>
|
16
|
+
# <article class=\"h-entry\">\n <h1 class=\"p-name\">Senior Cat Living</h1>\n
|
17
|
+
describe "html" do
|
18
|
+
describe "html" do
|
19
|
+
let(:html) { feed.to_html }
|
20
|
+
|
21
|
+
it "should match the example html" do
|
22
|
+
html.gsub(/\\n|\s/, '').should eq File.open("spec/support/example.html").read.gsub(/\\n|\s/, '')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
15
27
|
end
|
data/spec/support/example.html
CHANGED
@@ -1,171 +1,168 @@
|
|
1
|
-
<
|
2
|
-
<
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
<article class="h-entry">
|
2
|
+
<h1 class="p-name">Senior Cat Living</h1>
|
3
|
+
<p class="woot p-summary woot">Signed up with 3 locations</p>
|
4
|
+
<p class="p-five">Signed up with 3 locations</p>
|
5
|
+
<time datetime="2012-08-26 20:09-0700" class="dt-published">
|
6
|
+
8:09pm on August 26th, 2012
|
7
|
+
</time>
|
8
|
+
<a class="p-category" href="http://g5.com/tag/new-customer" rel="tag">
|
9
|
+
New Customer
|
10
|
+
</a>
|
11
|
+
<a class="u-url u-uid" href="http://g5.com/feed/entries/2012-08-26-20-09-0700">
|
12
|
+
http://g5.com/feed/entries/2012-08-26-20-09-0700
|
13
|
+
</a>
|
14
|
+
<div class="p-author h-card">
|
15
|
+
<p class="p-name">Jessica Suttles</p>
|
16
|
+
<a class="u-email" href="mailto:jessica.suttles@getg5.com">
|
17
|
+
jessica.suttles@getg5.com
|
11
18
|
</a>
|
12
|
-
<a class="u-url u-uid" href="http
|
13
|
-
http
|
19
|
+
<a class="u-url u-uid" href="http//g5.com/authors/jessica-suttles">
|
20
|
+
http//g5.com/authors/jessica-suttles
|
14
21
|
</a>
|
15
|
-
<
|
16
|
-
|
17
|
-
|
18
|
-
|
22
|
+
<a class="u-url u-uid" href="http//g5.com/authors/jessica-suttlez">
|
23
|
+
http//g5.com/authors/jessica-suttlez
|
24
|
+
</a>
|
25
|
+
|
26
|
+
</div>
|
27
|
+
<div class="p-author h-card">
|
28
|
+
<p class="p-name">Bookis Smuin</p>
|
29
|
+
<a class="u-email" href="mailto:bookis.smuin@getg5.com">
|
30
|
+
bookis.smuin@getg5.com
|
31
|
+
</a>
|
32
|
+
<a class="u-url u-uid" href="http//g5.com/authors/bookis-smuin">
|
33
|
+
http//g5.com/authors/bookis-smuin
|
34
|
+
</a>
|
35
|
+
</div>
|
36
|
+
|
37
|
+
<dl class="e-content">
|
38
|
+
<dt>Customer</dt>
|
39
|
+
<dd class="h-card">
|
40
|
+
<p class="p-name">Senior Cat Living</p>
|
41
|
+
<a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living">
|
42
|
+
http//g5.com/customers/senior-cat-living
|
19
43
|
</a>
|
20
|
-
|
21
|
-
|
44
|
+
</dd>
|
45
|
+
<dt>Corporate</dt>
|
46
|
+
<dd class="h-card">
|
47
|
+
<p class="p-name">Senior Cat Living Corporate</p>
|
48
|
+
<a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living/corporate">
|
49
|
+
http//g5.com/customers/senior-cat-living/corporate
|
22
50
|
</a>
|
23
|
-
|
24
|
-
|
51
|
+
</dd>
|
52
|
+
<dt>Locations</dt>
|
53
|
+
<dd class="h-card">
|
54
|
+
<p class="p-name">Senior Cat Living Location 1</p>
|
55
|
+
<a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living/locations/1">
|
56
|
+
http//g5.com/customers/senior-cat-living/locations/1
|
25
57
|
</a>
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
<
|
30
|
-
|
31
|
-
bookis.smuin@getg5.com
|
58
|
+
</dd>
|
59
|
+
<dd class="h-card">
|
60
|
+
<p class="p-name">Senior Cat Living Location 2</p>
|
61
|
+
<a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living/locations/2">
|
62
|
+
http//g5.com/customers/senior-cat-living/locations/2
|
32
63
|
</a>
|
33
|
-
|
34
|
-
|
64
|
+
</dd>
|
65
|
+
<dd class="h-card">
|
66
|
+
<p class="p-name">Senior Cat Living Location 3</p>
|
67
|
+
<a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living/locations/3">
|
68
|
+
http//g5.com/customers/senior-cat-living/locations/3
|
35
69
|
</a>
|
36
|
-
</
|
37
|
-
|
38
|
-
<
|
39
|
-
<
|
40
|
-
<
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
</
|
46
|
-
<
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
<a class="u-url u-uid" href="http//g5.com/features/content">
|
76
|
-
http//g5.com/feature/content
|
77
|
-
</a>
|
78
|
-
</dd>
|
79
|
-
<dd class="h-product">
|
80
|
-
<p class="p-name">Insight</p>
|
81
|
-
<a class="u-url u-uid" href="http//g5.com/features/insight">
|
82
|
-
http//g5.com/feature/insight
|
83
|
-
</a>
|
84
|
-
</dd>
|
85
|
-
<dd class="h-product">
|
86
|
-
<p class="p-name">Support</p>
|
87
|
-
<a class="u-url u-uid" href="http//g5.com/features/support">
|
88
|
-
http//g5.com/feature/support
|
89
|
-
</a>
|
90
|
-
</dd>
|
91
|
-
</dl>
|
92
|
-
</article>
|
93
|
-
<article class="h-entry">
|
94
|
-
<h1 class="p-name">Senior Cat Living</h1>
|
95
|
-
<p class="woot p-summary woot">Signed up with 3 locations</p>
|
96
|
-
<p class="p-five">Signed up with 3 locations</p>
|
97
|
-
<time datetime="2012-08-26 20:09-0700" class="dt-published">
|
98
|
-
8:09pm on August 26th, 2012
|
99
|
-
</time>
|
100
|
-
<a class="p-category" href="http://g5.com/tag/new-customer" rel="tag">
|
101
|
-
New Customer
|
70
|
+
</dd>
|
71
|
+
<dt>Features</dt>
|
72
|
+
<dd class="h-product">
|
73
|
+
<p class="p-name">Content</p>
|
74
|
+
<a class="u-url u-uid" href="http//g5.com/features/content">
|
75
|
+
http//g5.com/feature/content
|
76
|
+
</a>
|
77
|
+
</dd>
|
78
|
+
<dd class="h-product">
|
79
|
+
<p class="p-name">Insight</p>
|
80
|
+
<a class="u-url u-uid" href="http//g5.com/features/insight">
|
81
|
+
http//g5.com/feature/insight
|
82
|
+
</a>
|
83
|
+
</dd>
|
84
|
+
<dd class="h-product">
|
85
|
+
<p class="p-name">Support</p>
|
86
|
+
<a class="u-url u-uid" href="http//g5.com/features/support">
|
87
|
+
http//g5.com/feature/support
|
88
|
+
</a>
|
89
|
+
</dd>
|
90
|
+
</dl>
|
91
|
+
</article>
|
92
|
+
<article class="h-entry">
|
93
|
+
<h1 class="p-name">Senior Cat Living</h1>
|
94
|
+
<p class="woot p-summary woot">Signed up with 3 locations</p>
|
95
|
+
<p class="p-five">Signed up with 3 locations</p>
|
96
|
+
<time datetime="2012-08-26 20:09-0700" class="dt-published">
|
97
|
+
8:09pm on August 26th, 2012
|
98
|
+
</time>
|
99
|
+
<a class="p-category" href="http://g5.com/tag/new-customer" rel="tag">
|
100
|
+
New Customer
|
101
|
+
</a>
|
102
|
+
<a class="u-url u-uid" href="http://g5.com/feed/entries/2012-08-26-20-09-0700">
|
103
|
+
http://g5.com/feed/entries/2012-08-26-20-09-0700
|
104
|
+
</a>
|
105
|
+
<div class="p-author h-card">
|
106
|
+
<p class="p-name">Jessica Suttles</p>
|
107
|
+
<a class="u-email" href="mailto:jessica.suttles@getg5.com">
|
108
|
+
jessica.suttles@getg5.com
|
102
109
|
</a>
|
103
|
-
<a class="u-url u-uid" href="http
|
104
|
-
http
|
110
|
+
<a class="u-url u-uid" href="http//g5.com/authors/jessica-suttles">
|
111
|
+
http//g5.com/authors/jessica-suttles
|
105
112
|
</a>
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
</
|
111
|
-
<a class="u-url u-uid" href="http//g5.com/
|
112
|
-
http//g5.com/
|
113
|
-
</a>
|
114
|
-
</
|
115
|
-
<
|
116
|
-
|
117
|
-
<
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
<
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
<
|
131
|
-
<
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
</
|
137
|
-
<
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
<
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
<
|
150
|
-
<
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
</
|
156
|
-
<
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
<dd class="h-product">
|
163
|
-
<p class="p-name">Support</p>
|
164
|
-
<a class="u-url u-uid" href="http//g5.com/features/support">
|
165
|
-
http//g5.com/feature/support
|
166
|
-
</a>
|
167
|
-
</dd>
|
168
|
-
</dl>
|
169
|
-
</article>
|
170
|
-
|
171
|
-
</section>
|
113
|
+
</div>
|
114
|
+
<dl class="e-content">
|
115
|
+
<dt>Customer</dt>
|
116
|
+
<dd class="h-card">
|
117
|
+
<p class="p-name">Senior Cat Living</p>
|
118
|
+
<a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living">
|
119
|
+
http//g5.com/customers/senior-cat-living
|
120
|
+
</a>
|
121
|
+
</dd>
|
122
|
+
<dt>Corporate</dt>
|
123
|
+
<dd class="h-card">
|
124
|
+
<p class="p-name">Senior Cat Living Corporate</p>
|
125
|
+
<a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living/corporate">
|
126
|
+
http//g5.com/customers/senior-cat-living/corporate
|
127
|
+
</a>
|
128
|
+
</dd>
|
129
|
+
<dt>Locations</dt>
|
130
|
+
<dd class="h-card">
|
131
|
+
<p class="p-name">Senior Cat Living Location 1</p>
|
132
|
+
<a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living/locations/1">
|
133
|
+
http//g5.com/customers/senior-cat-living/locations/1
|
134
|
+
</a>
|
135
|
+
</dd>
|
136
|
+
<dd class="h-card">
|
137
|
+
<p class="p-name">Senior Cat Living Location 2</p>
|
138
|
+
<a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living/locations/2">
|
139
|
+
http//g5.com/customers/senior-cat-living/locations/2
|
140
|
+
</a>
|
141
|
+
</dd>
|
142
|
+
<dd class="h-card">
|
143
|
+
<p class="h-five p-name">Senior Cat Living Location 3</p>
|
144
|
+
<a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living/locations/3">
|
145
|
+
http//g5.com/customers/senior-cat-living/locations/3
|
146
|
+
</a>
|
147
|
+
</dd>
|
148
|
+
<dt>Features</dt>
|
149
|
+
<dd class="h-product">
|
150
|
+
<p class="p-name">Content</p>
|
151
|
+
<a class="u-url u-uid" href="http//g5.com/features/content">
|
152
|
+
http//g5.com/feature/content
|
153
|
+
</a>
|
154
|
+
</dd>
|
155
|
+
<dd class="h-product">
|
156
|
+
<p class="p-name">Insight</p>
|
157
|
+
<a class="u-url u-uid" href="http//g5.com/features/insight">
|
158
|
+
http//g5.com/feature/insight
|
159
|
+
</a>
|
160
|
+
</dd>
|
161
|
+
<dd class="h-product">
|
162
|
+
<p class="p-name">Support</p>
|
163
|
+
<a class="u-url u-uid" href="http//g5.com/features/support">
|
164
|
+
http//g5.com/feature/support
|
165
|
+
</a>
|
166
|
+
</dd>
|
167
|
+
</dl>
|
168
|
+
</article>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hentry_consumer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
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-
|
12
|
+
date: 2012-10-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|