hentry_consumer 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in hentry_consumer.gemspec
4
+ gem 'simplecov', :require => false, :group => :test
5
+
4
6
  gemspec
data/README.md CHANGED
@@ -34,7 +34,7 @@ The returned Object structure looks something like this:
34
34
 
35
35
  ## Current Version
36
36
 
37
- 0.8.0
37
+ 0.8.1
38
38
 
39
39
 
40
40
  ## Requirements
@@ -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
@@ -1,3 +1,3 @@
1
1
  module HentryConsumer
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
  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
@@ -1,4 +1,4 @@
1
- require 'hentry_consumer'
1
+ require 'spec_helper'
2
2
 
3
3
  describe HentryConsumer::FormatRules do
4
4
  before do
@@ -1,4 +1,4 @@
1
- require 'hentry_consumer'
1
+ require 'spec_helper'
2
2
 
3
3
  describe HentryConsumer::HCard do
4
4
  before do
@@ -1,4 +1,4 @@
1
- require 'hentry_consumer'
1
+ require 'spec_helper'
2
2
 
3
3
  describe HentryConsumer::HEntry do
4
4
  describe "example.html" do
@@ -1,4 +1,4 @@
1
- require 'hentry_consumer'
1
+ require 'spec_helper'
2
2
 
3
3
  describe HentryConsumer::HFeed do
4
4
  let(:feed) { HentryConsumer.parse(File.open("spec/support/example.html")) }
@@ -1,4 +1,4 @@
1
- require 'hentry_consumer'
1
+ require 'spec_helper'
2
2
 
3
3
  describe HentryConsumer do
4
4
 
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,5 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
1
4
  require 'rubygems'
2
5
  require 'hentry_consumer'
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.0
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: 2012-12-14 00:00:00.000000000 Z
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