hmachine 0.1.0 → 0.1.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.
Files changed (49) hide show
  1. data/README.md +4 -133
  2. data/hmachine.gemspec +15 -79
  3. metadata +22 -89
  4. data/.gitignore +0 -3
  5. data/Gemfile +0 -11
  6. data/Gemfile.lock +0 -51
  7. data/Rakefile +0 -53
  8. data/bin/hmachine +0 -99
  9. data/test/fixtures/hcard/commercenet.html +0 -21
  10. data/test/fixtures/hcard/geo.html +0 -28
  11. data/test/fixtures/huffduffer.html +0 -466
  12. data/test/fixtures/likeorhate.html +0 -48
  13. data/test/fixtures/rel_license.html +0 -4
  14. data/test/fixtures/test-fixture/hcard/hcard1.html +0 -147
  15. data/test/fixtures/test-fixture/hcard/hcard11.html +0 -123
  16. data/test/fixtures/test-fixture/hcard/hcard12.html +0 -178
  17. data/test/fixtures/test-fixture/hcard/hcard17.html +0 -165
  18. data/test/fixtures/test-fixture/hcard/hcard2.html +0 -264
  19. data/test/fixtures/test-fixture/hcard/hcard3.html +0 -144
  20. data/test/fixtures/test-fixture/hcard/hcard4.html +0 -117
  21. data/test/fixtures/test-fixture/hcard/hcard5.html +0 -119
  22. data/test/fixtures/test-fixture/hcard/hcard6.html +0 -188
  23. data/test/fixtures/test-fixture/hcard/hcard7.html +0 -188
  24. data/test/fixtures/test-fixture/hcard/hcard8.html +0 -130
  25. data/test/fixtures/test-fixture/hcard/hcard9.html +0 -111
  26. data/test/fixtures/test-fixture/hcard/hcard99.html +0 -215
  27. data/test/fixtures/test-fixture/value-class-date-time/value-dt-test-YYYY-MM-DD--HH-MM.html +0 -9
  28. data/test/fixtures/test-fixture/value-class-date-time/value-dt-test-abbr-YYYY-MM-DD--HH-MM.html +0 -4
  29. data/test/fixtures/xfn.html +0 -198
  30. data/test/fixtures/xmdp.html +0 -32
  31. data/test/fixtures/xoxo.html +0 -51
  32. data/test/hmachine_test.rb +0 -133
  33. data/test/microformat/adr_test.rb +0 -47
  34. data/test/microformat/geo_test.rb +0 -66
  35. data/test/microformat/hcard_test.rb +0 -510
  36. data/test/microformat/rellicense_test.rb +0 -36
  37. data/test/microformat/reltag_test.rb +0 -61
  38. data/test/microformat/votelinks_test.rb +0 -44
  39. data/test/microformat/xfn_test.rb +0 -28
  40. data/test/microformat/xmdp_test.rb +0 -16
  41. data/test/microformat/xoxo_test.rb +0 -51
  42. data/test/microformat_test.rb +0 -20
  43. data/test/pattern/date_time_test.rb +0 -55
  44. data/test/pattern/value_class_test.rb +0 -33
  45. data/test/pattern_test.rb +0 -132
  46. data/test/posh/anchor_test.rb +0 -41
  47. data/test/posh/base_test.rb +0 -150
  48. data/test/posh/definition_list_test.rb +0 -38
  49. data/test/test_helper.rb +0 -32
@@ -1,41 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
-
3
- class PoshAnchorTest < Test::Unit::TestCase
4
- setup do
5
- @html = '<a href="http://something.com" rel="me friend" title="This is a link" type="good">Link to something</a>'
6
- @doc = Nokogiri.parse(@html)
7
- end
8
-
9
- should 'parse all anchor tags from a document' do
10
- link = HMachine::POSH::Anchor.parse(@doc)
11
- assert_equal HMachine::POSH::Anchor, link.class
12
- end
13
-
14
- should 'have rel values' do
15
- link = HMachine::POSH::Anchor.parse(@doc)
16
- assert_respond_to link, :rel
17
- assert_equal 2, link.rel.count
18
- assert_equal 'me', link.rel.first
19
- end
20
-
21
- should 'have a url' do
22
- link = HMachine::POSH::Anchor.parse(@doc)
23
- assert_respond_to link, :url
24
- assert_equal 'http://something.com', link.url
25
- end
26
-
27
- should 'have some text' do
28
- link = HMachine::POSH::Anchor.parse(@doc)
29
- assert_respond_to link, :text
30
- assert_respond_to link, :content
31
- assert_equal 'Link to something', link.text
32
- assert_equal link.text, link.content
33
- end
34
-
35
- should 'have a title' do
36
- link = HMachine::POSH::Anchor.parse(@doc)
37
- assert_respond_to link, :type
38
- assert_equal 'good', link.type
39
- end
40
-
41
- end
@@ -1,150 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
-
3
- class PoshBaseTest < Test::Unit::TestCase
4
- setup do
5
- @html = get_fixture('hcard/commercenet.html')
6
- @doc = Nokogiri.parse(@html, 'http://foobar.com/')
7
- end
8
-
9
- describe 'Inheritance' do
10
- setup do
11
- @test_class = Class.new(HMachine::POSH::Base)
12
- @test_class.name :vcard
13
- end
14
-
15
- should "add a property to its group of properties" do
16
- property = @test_class.add_property(:fn)
17
- assert_equal property, @test_class.properties[:fn]
18
- end
19
-
20
- should 'further refine a property with a block' do
21
- property = @test_class.add_property(:fn) do
22
- add_property(:n)
23
- end
24
- assert_equal property[:n], @test_class.properties[:fn][:n]
25
- end
26
-
27
- should 'find a property' do
28
- property = @test_class.add_property(:fn)
29
- assert_equal property, @test_class[:fn]
30
- end
31
-
32
- should 'have one property' do
33
- property = @test_class.has_one!(:fn)
34
- assert_respond_to @test_class, :one
35
- assert_equal 1, @test_class.one.length
36
- assert @test_class.one.include?(property)
37
- end
38
-
39
- should 'has many properties' do
40
- property = @test_class.has_many!(:tel)
41
- assert_respond_to @test_class, :many
42
- assert_equal 1, @test_class.many.length
43
- assert_equal property, @test_class.many.first
44
- end
45
-
46
- should 'parse by properties' do
47
- property = @test_class.has_one :fn
48
- assert_equal property.first, @test_class.one.first
49
- assert_equal 'CommerceNet', @test_class.parse(@doc)[:fn]
50
- end
51
-
52
- should 'parse itself out of a document' do
53
- @test_class.has_one :fn
54
- assert_instance_of @test_class, @test_class.parse(@doc)
55
- end
56
-
57
- should 'have one property and define an instance method' do
58
- property = @test_class.has_one :fn
59
- assert_equal property.first, @test_class.instance_variable_get(:@has_one).first
60
- assert_respond_to @test_class.parse_first(@doc), :fn
61
- assert_equal property.first.parse_first(@doc), @test_class.parse(@doc).fn
62
- end
63
-
64
- should 'have many of a type of properties and define an instance method' do
65
- property = @test_class.has_many :tel
66
- assert_respond_to @test_class.parse(@doc), :tel
67
- end
68
-
69
- should 'subclasses retain properties' do
70
- @test_class.has_one :fn
71
- @test_class.has_many :tel
72
- klass = Class.new(@test_class)
73
- klass.name :vcard
74
- assert_equal @test_class.properties, klass.properties
75
- assert_equal @test_class.instance_variable_get(:@has_one), klass.instance_variable_get(:@has_one)
76
- assert_equal @test_class.instance_variable_get(:@has_many), klass.instance_variable_get(:@has_many)
77
- klass.has_one :foo
78
- assert !@test_class.properties.has_key?(:foo)
79
- assert klass.properties.has_key?(:foo)
80
- assert_respond_to klass.parse_first(@doc), :foo
81
- end
82
- end
83
-
84
- describe 'Instance' do
85
- setup do
86
- @klass = Class.new(HMachine::POSH::Base)
87
- property = 'vcard'
88
- @doc = Nokogiri.parse(@html, 'http://foobar.com/')
89
- @klass.search { |doc| doc.css(".#{property}") }
90
- @klass.validate { |node| node['class'] && node['class'].split(' ').include?(property) }
91
- @node = @klass.find_in(@doc).first
92
- end
93
-
94
- should 'have a node' do
95
- assert_equal @node, @klass.new(@node).node
96
- end
97
-
98
- should 'have its own set of properties' do
99
- fn = @klass.has_one :fn
100
- @klass.has_many :foobar
101
- vcard = @klass.new(@node)
102
- assert vcard.properties.has_key?(:fn)
103
- assert !vcard.properties.has_key?(:foobar)
104
- assert_equal fn.first, vcard.properties[:fn]
105
- end
106
-
107
- should 'lookup a property value' do
108
- fn = @klass.has_one :fn
109
- vcard = @klass.new(@node)
110
- assert_equal vcard.to_h[:fn], vcard[:fn]
111
- assert_equal fn.first.parse_first(@node), vcard[:fn]
112
- end
113
-
114
- should 'convert to a hash' do
115
- fn = @klass.has_one :fn
116
- tel = @klass.has_many :tel
117
- @klass.has_many :foobar
118
- vcard = @klass.new(@node)
119
- assert vcard.to_h.has_key?(:fn)
120
- assert vcard.to_h.has_key?(:tel)
121
- assert !vcard.to_h.has_key?(:foobar)
122
- end
123
-
124
- should 'not search for properties in nested microformats' do
125
- nested = '<div class="vcard"><span class="fn">Mark Wunsch</span> and <div class="vcard"><span class="fn">Somebody else</span></div></div>'
126
- doc = Nokogiri::HTML.parse(nested)
127
- @klass.has_many :fn
128
- vcard = @klass.parse_first(doc)
129
- assert vcard.instance_variable_get(:@first_node) != vcard.node
130
- assert_equal "Mark Wunsch", vcard.fn
131
- end
132
-
133
- should 'have a DSL for defining properties' do
134
- @klass.has_one :fn
135
- @klass.has_many :tel
136
- @klass.has_many! :foobar
137
- vcard = @klass.new(@node)
138
- assert_respond_to vcard, :fn
139
- assert_respond_to vcard, :tel
140
- assert !vcard.respond_to?(:foobar)
141
- end
142
-
143
- should 'recall the source (url) of the document' do
144
- vcard = @klass.new(@node)
145
- assert_respond_to vcard, :source
146
- assert_equal 'http://foobar.com/', vcard.source
147
- end
148
-
149
- end
150
- end
@@ -1,38 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
-
3
- class PoshDefinitionListTest < Test::Unit::TestCase
4
- setup do
5
- @html = get_fixture('xmdp.html')
6
- @doc = Nokogiri.parse(@html)
7
- end
8
-
9
- should 'pull itself out of a document' do
10
- dl = HMachine::POSH::DefinitionList.parse_first(@doc)
11
- assert_equal HMachine::POSH::DefinitionList, dl.class
12
- end
13
-
14
- should 'build a hash out of a definition list' do
15
- dl = HMachine::POSH::DefinitionList.find_in(@doc).first
16
- dict = HMachine::POSH::DefinitionList.build_dictionary(dl)
17
- assert dict.has_key?(:rel)
18
- assert !dict.has_key?(:script)
19
- end
20
-
21
- should 'parse a defintion list' do
22
- dl = HMachine::POSH::DefinitionList.parse_first(@doc)
23
- assert_respond_to dl, :to_h
24
- assert dl.to_h.has_key?(:rel)
25
- assert dl.to_h[:rel].has_key?(:script)
26
- end
27
-
28
- should 'list its properties as its hash representation' do
29
- dl = HMachine::POSH::DefinitionList.parse_first(@doc)
30
- assert_equal dl.to_h, dl.properties
31
- end
32
-
33
- should 'have key lookup methods' do
34
- dl = HMachine::POSH::DefinitionList.parse_first(@doc)
35
- assert_equal dl.to_h[:rel], dl[:rel]
36
- end
37
-
38
- end
data/test/test_helper.rb DELETED
@@ -1,32 +0,0 @@
1
- begin
2
- # Try to require the preresolved locked set of gems.
3
- require File.expand_path('../.bundle/environment', __FILE__)
4
- rescue LoadError
5
- # Fall back on doing an unlocked resolve at runtime.
6
- require "rubygems"
7
- require "bundler"
8
- Bundler.setup
9
- end
10
-
11
- require 'test/unit'
12
- require 'contest'
13
- require 'redgreen'
14
- require 'fakeweb'
15
-
16
- begin
17
- require 'hmachine'
18
- rescue LoadError
19
- lib_path = File.join(File.dirname(__FILE__), '..', 'lib')
20
- $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
21
- require 'hmachine'
22
- end
23
-
24
- def get_fixture(filename)
25
- open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename}")).read
26
- end
27
-
28
- # http://microformats.org/wiki/test-fixture
29
- def test_fixture(filename)
30
- html = get_fixture('test-fixture/' + filename)
31
- doc = Nokogiri::HTML.parse(html).css('#uf').first
32
- end