hentry_consumer 0.1.3 → 0.2.0
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 +8 -7
- data/lib/hentry_consumer/format_rules.rb +6 -2
- data/lib/hentry_consumer/h_entry.rb +12 -11
- data/lib/hentry_consumer/version.rb +1 -1
- data/spec/lib/hentry_consumer/format_rules_spec.rb +9 -1
- data/spec/lib/hentry_consumer/h_card_spec.rb +2 -2
- data/spec/lib/hentry_consumer/h_entry_spec.rb +11 -11
- metadata +48 -61
data/README.md
CHANGED
@@ -5,13 +5,14 @@ serialized h-entry objects. The returned Object structure looks something like t
|
|
5
5
|
|
6
6
|
- HFeed
|
7
7
|
- HEntry
|
8
|
-
- name
|
9
|
-
- summary
|
10
|
-
- email
|
11
|
-
- content
|
12
|
-
- author
|
8
|
+
- [name]
|
9
|
+
- [summary]
|
10
|
+
- [email]
|
11
|
+
- [content]
|
12
|
+
- [author]
|
13
|
+
- bookmark
|
13
14
|
- HCard
|
14
|
-
- categories
|
15
|
+
- [categories]
|
15
16
|
- {}
|
16
17
|
- HEntry
|
17
18
|
- ...
|
@@ -21,7 +22,7 @@ serialized h-entry objects. The returned Object structure looks something like t
|
|
21
22
|
|
22
23
|
## Current Version
|
23
24
|
|
24
|
-
0.
|
25
|
+
0.2.0
|
25
26
|
|
26
27
|
|
27
28
|
## Requirements
|
@@ -1,13 +1,17 @@
|
|
1
1
|
module HentryConsumer
|
2
2
|
class FormatRules
|
3
3
|
REQUIRED = []
|
4
|
-
|
4
|
+
UNIQUE = [:uid, :bookmark]
|
5
5
|
class << self
|
6
6
|
def required?(format)
|
7
7
|
REQUIRED.include? format
|
8
8
|
end
|
9
9
|
def can_have_many?(format)
|
10
|
-
|
10
|
+
!unique?(format)
|
11
|
+
end
|
12
|
+
|
13
|
+
def unique?(format)
|
14
|
+
UNIQUE.include? format
|
11
15
|
end
|
12
16
|
end
|
13
17
|
end
|
@@ -3,7 +3,7 @@ module HentryConsumer
|
|
3
3
|
|
4
4
|
attr_accessor :name, :categories, :author, :content, :bookmark, :published_at, :summary
|
5
5
|
alias_method :authors, :author
|
6
|
-
|
6
|
+
|
7
7
|
def parse_elements(microformat)
|
8
8
|
FormatClass.each do |letter|
|
9
9
|
microformat.css(">*[class*=#{letter}-]").each do |attrs|
|
@@ -13,17 +13,17 @@ module HentryConsumer
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def to_json(*a)
|
18
|
-
{:items =>
|
18
|
+
{:items =>
|
19
19
|
[{
|
20
20
|
:type => ["h-entry"],
|
21
21
|
:properties => {
|
22
22
|
:name => self.name,
|
23
23
|
:categories => self.categories,
|
24
24
|
:author => self.author,
|
25
|
-
:content => self.content,
|
26
|
-
:bookmark => self.bookmark,
|
25
|
+
:content => self.content,
|
26
|
+
:bookmark => self.bookmark,
|
27
27
|
:published_at => self.published_at,
|
28
28
|
:summary => self.summary
|
29
29
|
}
|
@@ -34,21 +34,22 @@ module HentryConsumer
|
|
34
34
|
private
|
35
35
|
|
36
36
|
def parse_element(microformat, klass)
|
37
|
-
case klass
|
37
|
+
key, value = case klass
|
38
38
|
when 'p-author'
|
39
|
-
|
39
|
+
[symbolize_class(klass), HCard.new(microformat)]
|
40
40
|
when 'p-category'
|
41
41
|
self.categories ||= {}
|
42
42
|
self.categories[microformat.text.gsub('\n', " ").strip] = microformat["href"]
|
43
43
|
when 'e-content'
|
44
|
-
|
44
|
+
[:content, parse_content(microformat)]
|
45
45
|
when'dt-published'
|
46
|
-
|
46
|
+
[:published_at, microformat["datetime"]]
|
47
47
|
when "u-uid"
|
48
|
-
|
48
|
+
[:bookmark, microformat['href']]
|
49
49
|
else
|
50
|
-
|
50
|
+
[symbolize_class(klass), microformat.text.gsub('\n', " ").strip]
|
51
51
|
end
|
52
|
+
assign_value(key, value)
|
52
53
|
end
|
53
54
|
|
54
55
|
def parse_content(microformat)
|
@@ -3,7 +3,7 @@ require 'hentry_consumer'
|
|
3
3
|
describe HentryConsumer::FormatRules do
|
4
4
|
before do
|
5
5
|
stub_const("HentryConsumer::FormatRules::REQUIRED", [:url])
|
6
|
-
stub_const("HentryConsumer::FormatRules::
|
6
|
+
stub_const("HentryConsumer::FormatRules::UNIQUE", [:uid])
|
7
7
|
end
|
8
8
|
|
9
9
|
it "stubs correctly" do
|
@@ -17,5 +17,13 @@ describe HentryConsumer::FormatRules do
|
|
17
17
|
it "can have many" do
|
18
18
|
HentryConsumer::FormatRules.can_have_many?(:url).should be_true
|
19
19
|
end
|
20
|
+
|
21
|
+
it "can't have many" do
|
22
|
+
HentryConsumer::FormatRules.can_have_many?(:uid).should be_false
|
23
|
+
end
|
24
|
+
|
25
|
+
it "is unique" do
|
26
|
+
HentryConsumer::FormatRules.unique?(:uid).should be_true
|
27
|
+
end
|
20
28
|
|
21
29
|
end
|
@@ -3,14 +3,14 @@ require 'hentry_consumer'
|
|
3
3
|
describe HentryConsumer::HEntry do
|
4
4
|
before do
|
5
5
|
stub_const("HentryConsumer::FormatRules::REQUIRED", [:url, :email])
|
6
|
-
stub_const("HentryConsumer::FormatRules::
|
6
|
+
stub_const("HentryConsumer::FormatRules::UNIQUE", [:uid, :bookmark])
|
7
7
|
end
|
8
8
|
|
9
9
|
let(:result) { HentryConsumer.parse(File.open("spec/support/example.html")) }
|
10
10
|
let(:entry) { result.entries.first }
|
11
11
|
subject { entry.authors.first }
|
12
12
|
|
13
|
-
its(:name) { should eq "Jessica Suttles"}
|
13
|
+
its(:name) { should eq ["Jessica Suttles"]}
|
14
14
|
|
15
15
|
its(:emails) { should have(1).things }
|
16
16
|
its(:urls) { should have(2).things }
|
@@ -9,15 +9,15 @@ describe HentryConsumer::HEntry do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "has a name" do
|
12
|
-
entry.name.should eq "Senior Cat Living"
|
12
|
+
entry.name.should eq ["Senior Cat Living"]
|
13
13
|
end
|
14
14
|
|
15
15
|
it "has a summary" do
|
16
|
-
entry.summary.
|
16
|
+
entry.summary.should eq ["Signed up with 3 locations"]
|
17
17
|
end
|
18
18
|
|
19
19
|
it "has a time" do
|
20
|
-
entry.published_at.should eq "2012-08-26 20:09-0700"
|
20
|
+
entry.published_at.should eq ["2012-08-26 20:09-0700"]
|
21
21
|
end
|
22
22
|
|
23
23
|
it "has a bookmark" do
|
@@ -45,30 +45,30 @@ describe HentryConsumer::HEntry do
|
|
45
45
|
let(:content) { entry.content }
|
46
46
|
|
47
47
|
it "should be a blob of html" do
|
48
|
-
content.should match /Locations/
|
48
|
+
content.first.should match /Locations/
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should be a blob of html" do
|
52
|
-
content.should match /\<dt\>/
|
52
|
+
content.first.should match /\<dt\>/
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should be a blob of html" do
|
56
|
-
content.should_not match /time/
|
56
|
+
content.first.should_not match /time/
|
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
|
+
|
64
64
|
it { json["items"].should be_an_instance_of Array }
|
65
65
|
it { json["items"].first["type"].should include 'h-entry'}
|
66
|
-
it { json["items"].first["properties"]["name"].should eq 'Senior Cat Living'}
|
67
|
-
it { json["items"].first["properties"]["content"].should match /Locations/ }
|
66
|
+
it { json["items"].first["properties"]["name"].should eq ['Senior Cat Living']}
|
67
|
+
it { json["items"].first["properties"]["content"].first.should match /Locations/ }
|
68
68
|
it { json["items"].first["properties"]["author"].should be_an_instance_of Array }
|
69
69
|
it { json["items"].first["properties"]["author"].first["items"].first["type"].should include "h-card" }
|
70
70
|
it { json["items"].first["properties"]["bookmark"].should eq "http://g5.com/feed/entries/2012-08-26-20-09-0700" }
|
71
|
-
it { json["items"].first["properties"]["published_at"].should eq "2012-08-26 20:09-0700" }
|
71
|
+
it { json["items"].first["properties"]["published_at"].should eq ["2012-08-26 20:09-0700"] }
|
72
72
|
it { json["items"].first["properties"]["summary"].should be_an_instance_of Array }
|
73
73
|
end
|
74
74
|
|
metadata
CHANGED
@@ -1,60 +1,55 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: hentry_consumer
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 3
|
10
|
-
version: 0.1.3
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Bookis Smuin
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-10-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: nokogiri
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :runtime
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: json
|
36
23
|
prerelease: false
|
37
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
38
33
|
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
|
43
|
-
segments:
|
44
|
-
- 0
|
45
|
-
version: "0"
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
46
38
|
type: :runtime
|
47
|
-
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
48
46
|
description: A hATOM feed parser
|
49
|
-
email:
|
47
|
+
email:
|
50
48
|
- vegan.bookis@gmail.com
|
51
49
|
executables: []
|
52
|
-
|
53
50
|
extensions: []
|
54
|
-
|
55
51
|
extra_rdoc_files: []
|
56
|
-
|
57
|
-
files:
|
52
|
+
files:
|
58
53
|
- .gitignore
|
59
54
|
- Gemfile
|
60
55
|
- Guardfile
|
@@ -78,38 +73,30 @@ files:
|
|
78
73
|
- spec/support/example.html
|
79
74
|
homepage: https://github.com/G5/hentry_consumer
|
80
75
|
licenses: []
|
81
|
-
|
82
76
|
post_install_message:
|
83
77
|
rdoc_options: []
|
84
|
-
|
85
|
-
require_paths:
|
78
|
+
require_paths:
|
86
79
|
- lib
|
87
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
81
|
none: false
|
89
|
-
requirements:
|
90
|
-
- -
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
|
93
|
-
|
94
|
-
- 0
|
95
|
-
version: "0"
|
96
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
87
|
none: false
|
98
|
-
requirements:
|
99
|
-
- -
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
|
102
|
-
segments:
|
103
|
-
- 0
|
104
|
-
version: "0"
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
105
92
|
requirements: []
|
106
|
-
|
107
93
|
rubyforge_project:
|
108
94
|
rubygems_version: 1.8.24
|
109
95
|
signing_key:
|
110
96
|
specification_version: 3
|
111
|
-
summary: Takes in HTML containing an h-feed classed element and returns serialized
|
112
|
-
|
97
|
+
summary: Takes in HTML containing an h-feed classed element and returns serialized
|
98
|
+
data based on the Microformat 2 hEntry specs
|
99
|
+
test_files:
|
113
100
|
- spec/lib/hentry_consumer/format_rules_spec.rb
|
114
101
|
- spec/lib/hentry_consumer/h_card_spec.rb
|
115
102
|
- spec/lib/hentry_consumer/h_entry_spec.rb
|