hentry_consumer 0.8.0 → 0.8.1
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/Gemfile +2 -0
- data/README.md +1 -1
- data/lib/hentry_consumer/element.rb +4 -17
- data/lib/hentry_consumer/version.rb +1 -1
- data/spec/lib/hentry_consumer/element_spec.rb +50 -0
- data/spec/lib/hentry_consumer/format_rules_spec.rb +1 -1
- data/spec/lib/hentry_consumer/h_card_spec.rb +1 -1
- data/spec/lib/hentry_consumer/h_entry_spec.rb +1 -1
- data/spec/lib/hentry_consumer/h_feed_spec.rb +1 -1
- data/spec/lib/hentry_consumer_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- metadata +4 -2
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module HentryConsumer
|
|
2
2
|
class Element
|
|
3
3
|
attr_accessor :element, :items
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
# If a single element is give, return that
|
|
6
6
|
# If many elements are given, return as array
|
|
7
7
|
def initialize(element)
|
|
@@ -18,7 +18,7 @@ module HentryConsumer
|
|
|
18
18
|
# just give me a simple array
|
|
19
19
|
end.flatten.compact
|
|
20
20
|
elsif elements.is_a?(Nokogiri::XML::Element)
|
|
21
|
-
parse_element(elements)
|
|
21
|
+
parse_element(elements).flatten.compact
|
|
22
22
|
else
|
|
23
23
|
nil # nothing to see here, move along
|
|
24
24
|
end
|
|
@@ -43,7 +43,7 @@ module HentryConsumer
|
|
|
43
43
|
|
|
44
44
|
# :(
|
|
45
45
|
def cleanse_classes(classes)
|
|
46
|
-
if classes =~ /(h-card)/
|
|
46
|
+
if classes =~ /(h-card)/
|
|
47
47
|
if classes =~ /(p-author)/ || classes =~ /(e-g5-client)/
|
|
48
48
|
classes.gsub!(/h-card/, "")
|
|
49
49
|
end
|
|
@@ -60,19 +60,6 @@ module HentryConsumer
|
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
-
def parse_h_card(element)
|
|
64
|
-
HCard.new(element.children)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def parse_h_entry(element)
|
|
68
|
-
HEntry.new(element.children)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
def symbolize_class(c)
|
|
73
|
-
c.to_s.downcase.gsub(/\w{1,2}-/, "").to_sym
|
|
74
|
-
end
|
|
75
|
-
|
|
76
63
|
def [](key)
|
|
77
64
|
self.send(key)
|
|
78
65
|
end
|
|
@@ -107,7 +94,7 @@ module HentryConsumer
|
|
|
107
94
|
def to_html
|
|
108
95
|
@element.to_html
|
|
109
96
|
end
|
|
110
|
-
|
|
97
|
+
|
|
111
98
|
def to_xml
|
|
112
99
|
@element.to_xml
|
|
113
100
|
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe HentryConsumer::Element do
|
|
4
|
+
let(:html) { "spec/support/example.html" }
|
|
5
|
+
let(:nokogiri) { Nokogiri::HTML(open(html).read).css('.h-entry').children }
|
|
6
|
+
let(:element) { HentryConsumer::Element.new(nokogiri) }
|
|
7
|
+
|
|
8
|
+
describe "#initialize" do
|
|
9
|
+
# Element can't actually parse anything because it doesn't have any parse_<format> methods defined
|
|
10
|
+
it "doesn't have any items" do
|
|
11
|
+
element.items.should be_empty
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "assigns the nokogiri to element" do
|
|
15
|
+
element.element.should eq nokogiri
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
describe "#parse_elements" do
|
|
19
|
+
describe "nodeset" do
|
|
20
|
+
it "returns an empty array" do
|
|
21
|
+
element.parse_elements(nokogiri).should be_empty
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "element" do
|
|
26
|
+
it "returns an empty array" do
|
|
27
|
+
element.parse_elements(nokogiri.first).should be_empty
|
|
28
|
+
end
|
|
29
|
+
it "calls parse microformat for itself" do
|
|
30
|
+
element.should_receive(:parse_microformat).with(nokogiri.first, "p-name").and_return(nil)
|
|
31
|
+
element.parse_elements(nokogiri.first)
|
|
32
|
+
end
|
|
33
|
+
it "calls parse element for itselt" do
|
|
34
|
+
element.should_receive(:parse_element).once.and_return([nil])
|
|
35
|
+
element.parse_elements(nokogiri.first)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe "#to_hash" do
|
|
41
|
+
it "doesn't have much to it" do
|
|
42
|
+
element.to_hash.should eq({:type => ["element"], :properties => {:items => []}})
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
describe "#to_json" do
|
|
46
|
+
it "pretty much just looks like hash" do
|
|
47
|
+
JSON.parse(element.to_json).should eq({"type" => ["element"], "properties" => {"items" => []}})
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
data/spec/spec_helper.rb
CHANGED
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.8.
|
|
4
|
+
version: 0.8.1
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2013-01-24 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: nokogiri
|
|
@@ -130,6 +130,7 @@ files:
|
|
|
130
130
|
- lib/hentry_consumer/h_entry.rb
|
|
131
131
|
- lib/hentry_consumer/h_feed.rb
|
|
132
132
|
- lib/hentry_consumer/version.rb
|
|
133
|
+
- spec/lib/hentry_consumer/element_spec.rb
|
|
133
134
|
- spec/lib/hentry_consumer/format_rules_spec.rb
|
|
134
135
|
- spec/lib/hentry_consumer/h_card_spec.rb
|
|
135
136
|
- spec/lib/hentry_consumer/h_entry_spec.rb
|
|
@@ -164,6 +165,7 @@ specification_version: 3
|
|
|
164
165
|
summary: Parses HTML containing one or more h-entry elements and returns serialized
|
|
165
166
|
data based on the microformat 2 spec
|
|
166
167
|
test_files:
|
|
168
|
+
- spec/lib/hentry_consumer/element_spec.rb
|
|
167
169
|
- spec/lib/hentry_consumer/format_rules_spec.rb
|
|
168
170
|
- spec/lib/hentry_consumer/h_card_spec.rb
|
|
169
171
|
- spec/lib/hentry_consumer/h_entry_spec.rb
|