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 CHANGED
@@ -22,7 +22,7 @@ serialized h-entry objects. The returned Object structure looks something like t
22
22
 
23
23
  ## Current Version
24
24
 
25
- 0.2.0
25
+ 0.3.0
26
26
 
27
27
 
28
28
  ## Requirements
@@ -1,12 +1,23 @@
1
1
  module HentryConsumer
2
2
  class Element
3
+ attr_accessor :element
4
+
3
5
  def initialize(microformat)
4
- parse_elements(microformat)
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(microformat)
18
+ def parse_elements
8
19
  FormatClass.each do |letter|
9
- microformat.css(">*[class*=#{letter}-]").each do |a|
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(microformat)
7
+ def parse_elements
8
8
  FormatClass.each do |letter|
9
- microformat.css(">*[class*=#{letter}-]").each do |attrs|
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
@@ -14,6 +14,10 @@ module HentryConsumer
14
14
  end
15
15
  end
16
16
 
17
+ def to_html
18
+ self.entries.collect(&:to_html).join
19
+ end
20
+
17
21
  def to_json(*a)
18
22
  {:items =>
19
23
  [{
@@ -1,3 +1,3 @@
1
1
  module HentryConsumer
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -9,4 +9,5 @@ module HentryConsumer
9
9
  def self.parse(html)
10
10
  HFeed.new(html)
11
11
  end
12
+
12
13
  end
@@ -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
@@ -1,171 +1,168 @@
1
- <section class="">
2
- <article class="h-entry">
3
- <h1 class="p-name">Senior Cat Living</h1>
4
- <p class="woot p-summary woot">Signed up with 3 locations</p>
5
- <p class="p-five">Signed up with 3 locations</p>
6
- <time datetime="2012-08-26 20:09-0700" class="dt-published">
7
- 8:09pm on August 26th, 2012
8
- </time>
9
- <a class="p-category" href="http://g5.com/tag/new-customer" rel="tag">
10
- New Customer
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://g5.com/feed/entries/2012-08-26-20-09-0700">
13
- http://g5.com/feed/entries/2012-08-26-20-09-0700
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
- <div class="p-author h-card">
16
- <p class="p-name">Jessica Suttles</p>
17
- <a class="u-email" href="mailto:jessica.suttles@getg5.com">
18
- jessica.suttles@getg5.com
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
- <a class="u-url u-uid" href="http//g5.com/authors/jessica-suttles">
21
- http//g5.com/authors/jessica-suttles
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
- <a class="u-url u-uid" href="http//g5.com/authors/jessica-suttlez">
24
- http//g5.com/authors/jessica-suttlez
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
- </div>
28
- <div class="p-author h-card">
29
- <p class="p-name">Bookis Smuin</p>
30
- <a class="u-email" href="mailto:bookis.smuin@getg5.com">
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
- <a class="u-url u-uid" href="http//g5.com/authors/bookis-smuin">
34
- http//g5.com/authors/bookis-smuin
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
- </div>
37
-
38
- <dl class="e-content">
39
- <dt>Customer</dt>
40
- <dd class="h-card">
41
- <p class="p-name">Senior Cat Living</p>
42
- <a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living">
43
- http//g5.com/customers/senior-cat-living
44
- </a>
45
- </dd>
46
- <dt>Corporate</dt>
47
- <dd class="h-card">
48
- <p class="p-name">Senior Cat Living Corporate</p>
49
- <a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living/corporate">
50
- http//g5.com/customers/senior-cat-living/corporate
51
- </a>
52
- </dd>
53
- <dt>Locations</dt>
54
- <dd class="h-card">
55
- <p class="p-name">Senior Cat Living Location 1</p>
56
- <a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living/locations/1">
57
- http//g5.com/customers/senior-cat-living/locations/1
58
- </a>
59
- </dd>
60
- <dd class="h-card">
61
- <p class="p-name">Senior Cat Living Location 2</p>
62
- <a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living/locations/2">
63
- http//g5.com/customers/senior-cat-living/locations/2
64
- </a>
65
- </dd>
66
- <dd class="h-card">
67
- <p class="p-name">Senior Cat Living Location 3</p>
68
- <a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living/locations/3">
69
- http//g5.com/customers/senior-cat-living/locations/3
70
- </a>
71
- </dd>
72
- <dt>Features</dt>
73
- <dd class="h-product">
74
- <p class="p-name">Content</p>
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://g5.com/feed/entries/2012-08-26-20-09-0700">
104
- http://g5.com/feed/entries/2012-08-26-20-09-0700
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
- <div class="p-author h-card">
107
- <p class="p-name">Jessica Suttles</p>
108
- <a class="u-email" href="mailto:jessica.suttles@getg5.com">
109
- jessica.suttles@getg5.com
110
- </a>
111
- <a class="u-url u-uid" href="http//g5.com/authors/jessica-suttles">
112
- http//g5.com/authors/jessica-suttles
113
- </a>
114
- </div>
115
- <dl class="e-content">
116
- <dt>Customer</dt>
117
- <dd class="h-card">
118
- <p class="p-name">Senior Cat Living</p>
119
- <a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living">
120
- http//g5.com/customers/senior-cat-living
121
- </a>
122
- </dd>
123
- <dt>Corporate</dt>
124
- <dd class="h-card">
125
- <p class="p-name">Senior Cat Living Corporate</p>
126
- <a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living/corporate">
127
- http//g5.com/customers/senior-cat-living/corporate
128
- </a>
129
- </dd>
130
- <dt>Locations</dt>
131
- <dd class="h-card">
132
- <p class="p-name">Senior Cat Living Location 1</p>
133
- <a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living/locations/1">
134
- http//g5.com/customers/senior-cat-living/locations/1
135
- </a>
136
- </dd>
137
- <dd class="h-card">
138
- <p class="p-name">Senior Cat Living Location 2</p>
139
- <a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living/locations/2">
140
- http//g5.com/customers/senior-cat-living/locations/2
141
- </a>
142
- </dd>
143
- <dd class="h-card">
144
- <p class="h-five p-name">Senior Cat Living Location 3</p>
145
- <a class="u-url u-uid" href="http//g5.com/customers/senior-cat-living/locations/3">
146
- http//g5.com/customers/senior-cat-living/locations/3
147
- </a>
148
- </dd>
149
- <dt>Features</dt>
150
- <dd class="h-product">
151
- <p class="p-name">Content</p>
152
- <a class="u-url u-uid" href="http//g5.com/features/content">
153
- http//g5.com/feature/content
154
- </a>
155
- </dd>
156
- <dd class="h-product">
157
- <p class="p-name">Insight</p>
158
- <a class="u-url u-uid" href="http//g5.com/features/insight">
159
- http//g5.com/feature/insight
160
- </a>
161
- </dd>
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.2.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-16 00:00:00.000000000 Z
12
+ date: 2012-10-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri