hmachine 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/.gitignore +2 -2
  2. data/Gemfile +6 -4
  3. data/Gemfile.lock +51 -0
  4. data/README.md +123 -9
  5. data/Rakefile +12 -3
  6. data/bin/hmachine +99 -0
  7. data/hmachine.gemspec +132 -0
  8. data/lib/hmachine.rb +121 -12
  9. data/lib/hmachine/microformat.rb +39 -20
  10. data/lib/hmachine/microformat/adr.rb +22 -0
  11. data/lib/hmachine/microformat/geo.rb +48 -0
  12. data/lib/hmachine/microformat/hcard.rb +169 -11
  13. data/lib/hmachine/microformat/rellicense.rb +20 -0
  14. data/lib/hmachine/microformat/reltag.rb +38 -0
  15. data/lib/hmachine/microformat/votelinks.rb +42 -0
  16. data/lib/hmachine/microformat/xfn.rb +54 -0
  17. data/lib/hmachine/microformat/xmdp.rb +14 -0
  18. data/lib/hmachine/microformat/xoxo.rb +69 -0
  19. data/lib/hmachine/pattern.rb +26 -0
  20. data/lib/hmachine/pattern/abbr.rb +21 -0
  21. data/lib/hmachine/pattern/datetime.rb +75 -0
  22. data/lib/hmachine/pattern/typevalue.rb +32 -0
  23. data/lib/hmachine/pattern/url.rb +32 -0
  24. data/lib/hmachine/pattern/valueclass.rb +51 -0
  25. data/lib/hmachine/posh.rb +3 -0
  26. data/lib/hmachine/posh/anchor.rb +40 -0
  27. data/lib/hmachine/posh/base.rb +204 -0
  28. data/lib/hmachine/posh/definition_list.rb +41 -0
  29. data/test/fixtures/huffduffer.html +466 -0
  30. data/test/fixtures/likeorhate.html +48 -0
  31. data/test/fixtures/rel_license.html +4 -0
  32. data/test/fixtures/test-fixture/hcard/hcard1.html +147 -0
  33. data/test/fixtures/test-fixture/hcard/hcard11.html +123 -0
  34. data/test/fixtures/test-fixture/hcard/hcard12.html +178 -0
  35. data/test/fixtures/test-fixture/hcard/hcard17.html +165 -0
  36. data/test/fixtures/test-fixture/hcard/hcard2.html +264 -0
  37. data/test/fixtures/test-fixture/hcard/hcard3.html +144 -0
  38. data/test/fixtures/test-fixture/hcard/hcard4.html +117 -0
  39. data/test/fixtures/test-fixture/hcard/hcard5.html +119 -0
  40. data/test/fixtures/test-fixture/hcard/hcard6.html +188 -0
  41. data/test/fixtures/test-fixture/hcard/hcard7.html +188 -0
  42. data/test/fixtures/test-fixture/hcard/hcard8.html +130 -0
  43. data/test/fixtures/test-fixture/hcard/hcard9.html +111 -0
  44. data/test/fixtures/test-fixture/hcard/hcard99.html +215 -0
  45. data/test/fixtures/test-fixture/value-class-date-time/value-dt-test-YYYY-MM-DD--HH-MM.html +9 -0
  46. data/test/fixtures/test-fixture/value-class-date-time/value-dt-test-abbr-YYYY-MM-DD--HH-MM.html +4 -0
  47. data/test/fixtures/xfn.html +198 -0
  48. data/test/fixtures/xmdp.html +32 -0
  49. data/test/fixtures/xoxo.html +51 -0
  50. data/test/hmachine_test.rb +122 -6
  51. data/test/microformat/adr_test.rb +47 -0
  52. data/test/microformat/geo_test.rb +66 -0
  53. data/test/microformat/hcard_test.rb +487 -20
  54. data/test/microformat/rellicense_test.rb +36 -0
  55. data/test/microformat/reltag_test.rb +61 -0
  56. data/test/microformat/votelinks_test.rb +44 -0
  57. data/test/microformat/xfn_test.rb +28 -0
  58. data/test/microformat/xmdp_test.rb +16 -0
  59. data/test/microformat/xoxo_test.rb +51 -0
  60. data/test/microformat_test.rb +12 -34
  61. data/test/pattern/date_time_test.rb +55 -0
  62. data/test/pattern/value_class_test.rb +33 -0
  63. data/test/pattern_test.rb +132 -0
  64. data/test/posh/anchor_test.rb +41 -0
  65. data/test/posh/base_test.rb +150 -0
  66. data/test/posh/definition_list_test.rb +38 -0
  67. data/test/test_helper.rb +24 -6
  68. metadata +93 -15
  69. data/lib/hmachine/microformat/base.rb +0 -17
@@ -0,0 +1,66 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class GeoTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = HMachine::Microformat::Geo
6
+ end
7
+
8
+ should 'has a latitude and longitude' do
9
+ doc = Nokogiri.parse(%q{
10
+ <div class="geo">GEO:
11
+ <span class="latitude">37.386013</span>,
12
+ <span class="longitude">-122.082932</span>
13
+ </div>
14
+ })
15
+ geo = @klass.parse(doc)
16
+ assert_respond_to geo, :latitude
17
+ assert_respond_to geo, :longitude
18
+ assert_equal geo.latitude, geo.lat
19
+ assert_equal geo.longitude, geo.long
20
+ assert_equal '-122.082932', geo.long
21
+ assert_equal '37.386013', geo.lat
22
+ end
23
+
24
+ should 'use the abbreviation design pattern when applicable' do
25
+ doc = Nokogiri.parse(%q{
26
+ <div class="geo">
27
+ <abbr class="latitude" title="37.408183">N 37° 24.491</abbr>
28
+ <abbr class="longitude" title="-122.13855">W 122° 08.313</abbr>
29
+ </div>
30
+ })
31
+ geo = @klass.parse(doc)
32
+ assert_equal "37.408183", geo.lat
33
+ assert_equal "-122.13855", geo.long
34
+ end
35
+
36
+ should 'use the value class pattern' do
37
+ doc = Nokogiri.parse(%q{
38
+ <div class="geo">GEO:
39
+ <span class="latitude">Somewhere <span class="value">37.386013</span></span>,
40
+ <span class="longitude">Far Away <span class="value">-122.082932</span></span>
41
+ </div>
42
+ })
43
+ geo = @klass.parse(doc)
44
+ assert_equal '37.386013', geo.lat
45
+ assert_equal '-122.082932', geo.long
46
+ end
47
+
48
+ should 'spit out a google maps url' do
49
+ doc = Nokogiri.parse(%q{
50
+ <div class="geo">
51
+ <abbr class="latitude" title="37.408183">N 37° 24.491</abbr>
52
+ <abbr class="longitude" title="-122.13855">W 122° 08.313</abbr>
53
+ </div>
54
+ })
55
+ geo = @klass.parse(doc)
56
+ assert_equal "http://maps.google.com/?q=37.408183,-122.13855", geo.to_google_maps
57
+ end
58
+
59
+ should 'extract lat/long values from paired value' do
60
+ doc = Nokogiri.parse(%q(<abbr class="geo" title="37.77;-122.41">Northern California</abbr>))
61
+ geo = @klass.parse(doc)
62
+ assert_respond_to geo, :latitude
63
+ assert_equal '37.77', geo.lat
64
+ assert_equal '-122.41', geo.long
65
+ end
66
+ end
@@ -1,43 +1,510 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
3
  class HCardTest < Test::Unit::TestCase
4
- setup do
5
- @html = get_fixture('hcard/commercenet.html')
6
- @node = Nokogiri::HTML.parse(@html).css(HMachine::Microformat::HCard::ROOT_SELECTOR)[0]
7
- @hcard = HMachine::Microformat::HCard.new(@node)
4
+ @@klass = HMachine::Microformat::HCard
5
+
6
+ describe 'non test-fixture tests' do
7
+ def self.before_all
8
+ @doc ||= Nokogiri.parse(get_fixture('hcard/commercenet.html'))
9
+ @vcard ||= @@klass.parse(@doc)
10
+ end
11
+
12
+ setup do
13
+ @vcard = self.class.before_all
14
+ end
15
+
16
+ should 'be an organization' do
17
+ assert @vcard.organization?
18
+ end
19
+
20
+ should 'convert to a vcard' do
21
+ assert_respond_to @vcard, :to_vcard
22
+ end
23
+ end
24
+
25
+ # http://www.ufxtract.com/testsuite/hcard/hcard1.htm
26
+ describe 'single occurence test' do
27
+ def self.before_all
28
+ @doc ||= test_fixture('hcard/hcard1.html')
29
+ @vcard ||= @@klass.parse_first(@doc)
30
+ end
31
+
32
+ setup do
33
+ @vcard = self.class.before_all
34
+ end
35
+
36
+ test 'The fn (formatted name) is a singular value' do
37
+ assert_respond_to @vcard, :fn
38
+ assert @vcard.has_property?(:fn)
39
+ assert_equal 'John Doe', @vcard.fn
40
+ end
41
+
42
+ test 'The n (name) is a singular value' do
43
+ assert_respond_to @vcard, :n
44
+ assert @vcard.has_property?(:n)
45
+ end
46
+
47
+ test 'The bday (birthday) is a singular value' do
48
+ assert @vcard.has_property?(:bday)
49
+ assert_equal 1, @vcard.bday.mon
50
+ assert_equal 1, @vcard.bday.day
51
+ assert_equal 2000, @vcard.bday.year
52
+ end
53
+
54
+ test 'The class is a singular value' do
55
+ assert @vcard.has_property?(:class)
56
+ assert_equal 'Public', @vcard[:class]
57
+ end
58
+
59
+ test 'The geo is a singular value' do
60
+ assert_respond_to @vcard, :geo
61
+ assert @vcard.has_property?(:geo)
62
+ end
63
+
64
+ test 'The rev is a singular value' do
65
+ assert @vcard.has_property?(:rev)
66
+ assert_equal 1, @vcard.rev.mon
67
+ assert_equal 1, @vcard.rev.day
68
+ end
69
+
70
+ test 'The role is a singular value' do
71
+ assert @vcard.has_property?(:role)
72
+ assert_equal 'Designer', @vcard.role
73
+ end
74
+
75
+ test 'The sort-string is a singular value' do
76
+ assert @vcard.has_property?(:sort_string)
77
+ assert_equal 'John', @vcard.sort_string
78
+ end
79
+
80
+ test 'The tz is a singular value' do
81
+ assert @vcard.has_property?(:tz)
82
+ assert_equal -18000, @vcard.tz.utc_offset
83
+ end
84
+
85
+ test 'The uid is a singular value' do
86
+ assert @vcard.has_property?(:uid)
87
+ assert_equal 'com.johndoe/profiles/johndoe', @vcard.uid
88
+ end
8
89
  end
9
90
 
10
- describe 'Constants' do
11
- test "hCard's root class" do
12
- assert @hcard.class::ROOT_CLASS == 'vcard', "Root class is #{@hcard.class::ROOT_CLASS}"
91
+ # http://www.ufxtract.com/testsuite/hcard/hcard2.htm
92
+ describe 'multiple occurence test' do
93
+ def self.before_all
94
+ @doc ||= test_fixture('hcard/hcard2.html')
95
+ @vcard ||= @@klass.parse_first(@doc)
13
96
  end
14
-
15
- test "hCard's root selector" do
16
- assert @hcard.class::ROOT_SELECTOR == '.vcard', "Root selector is #{@hcard.class::ROOT_SELECTOR}"
97
+
98
+ setup do
99
+ @vcard = self.class.before_all
100
+ end
101
+
102
+ test 'The adr (address) is a optional multiple value' do
103
+ assert @vcard.has_property?(:adr)
104
+ end
105
+
106
+ test 'The email is a optional multiple value' do
107
+ assert @vcard.has_property?(:email)
108
+ end
109
+
110
+ test 'The org is a optional multiple value' do
111
+ assert @vcard.has_property?(:org)
112
+ end
113
+
114
+ test 'The tel is a optional multiple value' do
115
+ assert @vcard.has_property?(:tel)
116
+ end
117
+
118
+ test 'The agent is a optional multiple value' do
119
+ assert @vcard.has_property?(:agent)
120
+ assert_equal 'Dave Doe', @vcard.agent[1]
121
+ end
122
+
123
+ test 'The category is a optional multiple value' do
124
+ assert @vcard.has_property?(:category)
125
+ assert_equal 'development', @vcard.category[1]
126
+ end
127
+
128
+ test 'The key is a optional multiple value' do
129
+ assert @vcard.has_property?(:key)
130
+ assert_equal "hd02$Gfu*d%dh87KTa2=23934532479", @vcard.key
131
+ end
132
+
133
+ test 'The key is a optional multiple value' do
134
+ assert @vcard.has_property?(:label)
135
+ assert_equal "West Street, Brighton, United Kingdom", @vcard.label[1].split("\n").collect {|i| i.strip }.join(' ')
136
+ end
137
+
138
+ test 'The label is a optional multiple value' do
139
+ assert @vcard.has_property?(:label)
140
+ assert_equal "West Street, Brighton, United Kingdom", @vcard.label[1].split("\n").collect {|i| i.strip }.join(' ')
141
+ end
142
+
143
+ test 'The logo is a optional multiple value' do
144
+ assert @vcard.has_property?(:logo)
145
+ assert_equal "../images/logo.gif", @vcard.logo[1]
146
+ end
147
+
148
+ test 'The mailer is a optional multiple value' do
149
+ assert @vcard.has_property?(:mailer)
150
+ assert_equal "Outlook 2007", @vcard.mailer[1]
151
+ end
152
+
153
+ test 'The nickname is a optional multiple value' do
154
+ assert @vcard.has_property?(:nickname)
155
+ assert_equal "Lost boy", @vcard.nickname[1]
156
+ end
157
+
158
+ test 'The note is a optional multiple value' do
159
+ assert @vcard.has_property?(:note)
160
+ assert_equal "It can be a real problem booking a hotel room with the name John Doe.", @vcard.note[1]
161
+ end
162
+
163
+ test 'The photo is a optional multiple value' do
164
+ assert @vcard.has_property?(:photo)
165
+ assert_equal "../images/photo.gif", @vcard.photo
166
+ end
167
+
168
+ test 'The sound is a optional multiple value' do
169
+ assert @vcard.has_property?(:sound)
170
+ assert_equal 'Pronunciation of my name', @vcard.sound
171
+ end
172
+
173
+ test 'The title is a optional multiple value' do
174
+ assert @vcard.has_property?(:title)
175
+ assert_equal 'Owner', @vcard.title[1]
176
+ end
177
+
178
+ test 'The url is a optional multiple value' do
179
+ assert @vcard.has_property?(:url)
180
+ assert_equal "http://www.webfeetmedia.com/", @vcard.url[1]
181
+ end
182
+ end
183
+
184
+ # http://ufxtract.com/testsuite/hcard/hcard3.htm
185
+ describe 'adr single and multiple occurence test' do
186
+ def self.before_all
187
+ @doc ||= test_fixture('hcard/hcard3.html')
188
+ @vcard ||= @@klass.parse_first(@doc)
189
+ end
190
+
191
+ setup do
192
+ @vcard = self.class.before_all
193
+ end
194
+
195
+ test 'The type is a optional multiple value.' do
196
+ assert @vcard.adr.type.eql?(:work)
197
+ end
198
+
199
+ test 'The post-office-box is a optional singular value' do
200
+ assert_equal 'PO Box 46', @vcard.adr.post_office_box
201
+ end
202
+
203
+ test 'The street-address is a optional multiple value' do
204
+ assert_equal 'West Street', @vcard.adr.street_address[1]
205
+ end
206
+
207
+ test 'The extended-address is a optional singular value' do
208
+ assert_equal 'Suite 2', @vcard.adr.extended_address
209
+ end
210
+
211
+ test 'The region is a optional singular value' do
212
+ assert_equal 'East Sussex', @vcard.adr.region
213
+ end
214
+
215
+ test 'The locality is a optional singular value' do
216
+ assert_equal 'Brighton', @vcard.adr.locality
217
+ end
218
+
219
+ test 'The postal-code is a optional singular value' do
220
+ assert_equal 'BN1 3DF', @vcard.adr.postal_code
221
+ end
222
+
223
+ test 'The country-name is a optional singular value' do
224
+ assert_equal 'United Kingdom', @vcard.adr.country_name
225
+ end
226
+ end
227
+
228
+ # http://ufxtract.com/testsuite/hcard/hcard4.htm
229
+ describe 'n single and multiple occurence test' do
230
+ def self.before_all
231
+ @doc ||= test_fixture('hcard/hcard4.html')
232
+ @vcard ||= @@klass.parse_first(@doc)
233
+ end
234
+
235
+ setup do
236
+ @vcard = self.class.before_all
237
+ end
238
+
239
+ test 'The honorific-prefix is a optional multiple value' do
240
+ assert_equal 'Dr', @vcard.n[:honorific_prefix]
241
+ end
242
+
243
+ test 'The given-name is a optional multiple value' do
244
+ assert_equal 'John', @vcard.n[:given_name]
245
+ end
246
+
247
+ test 'The additional-name is a optional multiple value' do
248
+ assert_equal 'Peter', @vcard.n[:additional_name]
249
+ end
250
+
251
+ test 'The family-name is a optional multiple value' do
252
+ assert_equal 'Doe', @vcard.n[:family_name]
253
+ end
254
+
255
+ test 'The honorific-suffix is a optional multiple value' do
256
+ assert_equal 'PHD', @vcard.n[:honorific_suffix][1]
17
257
  end
18
258
  end
19
259
 
20
- describe "Inheritance" do
21
- test "hCard's wiki url" do
22
- assert @hcard.class.wiki_url == @hcard.class::WIKI_URL, "Wiki url is #{@hcard.class.wiki_url}"
260
+ # http://ufxtract.com/testsuite/hcard/hcard6.htm
261
+ describe 'extracting email addresses text' do
262
+ def self.before_all
263
+ @doc ||= test_fixture('hcard/hcard6.html')
264
+ @vcard ||= @@klass.parse(@doc)
265
+ end
266
+
267
+ setup do
268
+ @vcard = self.class.before_all
269
+ end
270
+
271
+ should 'collect the email address from href attribute' do
272
+ assert_equal 'john@example.com', @vcard[0].email
273
+ end
274
+
275
+ test 'Where a type is specified, but the value is not then the node text is the value' do
276
+ assert @vcard[1].email.has_key?(:internet)
277
+ assert_equal 'john@example.com', @vcard[1].email.values.first
278
+ end
279
+
280
+ should 'collect the email address from the node text' do
281
+ assert_equal 'john@example.com', @vcard[2].email
282
+ end
283
+
284
+ should 'find the type value. types are case insensitive' do
285
+ assert_equal :internet, @vcard[3].email[1][:type]
286
+ end
287
+
288
+ should 'not contain querystring "?subject=parser-test"' do
289
+ assert_equal 'john@example.com', @vcard[5].email
23
290
  end
24
291
 
25
- test "hCard's validation" do
26
- assert @hcard.class.validate(@node)
292
+ test 'Where a type is specified, but the value is not then the node text is the value' do
293
+ assert_equal 'john@example.com', @vcard[6].email[:value]
27
294
  end
28
295
  end
29
296
 
30
- test "rejects invalid nodes" do
31
- assert_raise RuntimeError do
32
- HMachine::Microformat::HCard.new(Nokogiri::HTML.parse(@html))
297
+ # http://ufxtract.com/testsuite/hcard/hcard7.htm
298
+ describe 'extracting tel number test' do
299
+ def self.before_all
300
+ @doc ||= test_fixture('hcard/hcard7.html')
301
+ @vcard ||= @@klass.parse(@doc)
302
+ end
303
+
304
+ setup do
305
+ @vcard = self.class.before_all
306
+ end
307
+
308
+ should 'collect the telephone number from the node text' do
309
+ assert_equal '01273 700100', @vcard[0].tel
310
+ end
311
+
312
+ should 'collect the telephone number from a descendant node with value property' do
313
+ assert_equal "01273 700100", @vcard[1].tel[:value]
314
+ end
315
+
316
+ should 'find the type value' do
317
+ assert @vcard[2].tel.first[:type].include?(:pcs)
318
+ end
319
+
320
+ test 'Where a type is specified, but the value is not then the node text is the value' do
321
+ assert_equal '01273 700301', @vcard[4].tel[:value]
33
322
  end
34
323
  end
35
324
 
36
- test 'retains original node' do
37
- assert @hcard.node == @node
325
+ # http://ufxtract.com/testsuite/hcard/hcard8.htm
326
+ describe 'extracting URLs test' do
327
+ def self.before_all
328
+ @doc ||= test_fixture('hcard/hcard8.html')
329
+ @vcard ||= @@klass.parse(@doc)
330
+ end
331
+
332
+ setup do
333
+ @vcard = self.class.before_all
334
+ end
335
+
336
+ should 'collect the URL from the a element' do
337
+ assert_equal 'http://example.com/johndoe/', @vcard.first.url
338
+ end
339
+
340
+ should 'collect the URL from the area element' do
341
+ assert_equal 'http://example.com/johndoe/', @vcard[1].url
342
+ end
343
+
344
+ should 'collect the URL of the image element' do
345
+ assert_equal 'http://ufxtract.com/testsuite/images/photo.gif', @vcard[2].photo
346
+ end
38
347
  end
39
348
 
349
+ # http://ufxtract.com/testsuite/hcard/hcard5.htm
350
+ describe 'multiple values in class attribute test' do
351
+ def self.before_all
352
+ @doc ||= test_fixture('hcard/hcard5.html')
353
+ @vcard ||= @@klass.parse(@doc)
354
+ end
355
+
356
+ setup do
357
+ @vcard = self.class.before_all
358
+ end
359
+
360
+ should 'find given-name value even if class attribute has multiple values' do
361
+ assert_equal 'John', @vcard.n[:given_name]
362
+ end
363
+
364
+ should 'find category value even if class and rel attribute have multiple values' do
365
+ assert_equal 'development', @vcard.category[1]
366
+ end
367
+
368
+ should 'find rev value even if class attribute has multiple values' do
369
+ assert @vcard.has_property?(:rev)
370
+ assert_equal 2008, @vcard.rev.year
371
+ assert_equal 1, @vcard.rev.mon
372
+ assert_equal 1, @vcard.rev.day
373
+ end
374
+ end
40
375
 
376
+ # http://ufxtract.com/testsuite/hcard/hcard11.htm
377
+ describe 'img element test' do
378
+ def self.before_all
379
+ @doc ||= test_fixture('hcard/hcard11.html')
380
+ @vcard ||= @@klass.parse(@doc)
381
+ end
382
+
383
+ setup do
384
+ @vcard = self.class.before_all
385
+ end
386
+
387
+ test 'The fn value should be taken from the alt attribute on a img element' do
388
+ assert_equal 'John Doe', @vcard[0].fn
389
+ end
390
+
391
+ test 'The given-name value should implied from the alt attribute' do
392
+ assert_equal 'John', @vcard[1].n[:given_name]
393
+ end
394
+
395
+ test 'The family-name value should implied from the alt attribute' do
396
+ assert_equal 'Doe', @vcard[2].n[:family_name]
397
+ end
398
+ end
399
+
400
+ # http://ufxtract.com/testsuite/hcard/hcard12.htm
401
+ describe 'abbr element test' do
402
+ def self.before_all
403
+ @doc ||= test_fixture('hcard/hcard12.html')
404
+ @vcard ||= @@klass.parse(@doc)
405
+ end
406
+
407
+ setup do
408
+ @vcard = self.class.before_all
409
+ end
410
+
411
+ should 'take the value from the abbr title attribute' do
412
+ assert_equal 'John Doe', @vcard.fn
413
+ assert_equal 'Mister', @vcard.n[:honorific_prefix]
414
+ assert_equal 'Jonathan', @vcard.n[:given_name]
415
+ assert_equal 'John', @vcard.n[:additional_name]
416
+ assert_equal 'JJ', @vcard.nickname
417
+ assert_equal '123 Fake Street', @vcard.adr[:street_address]
418
+ assert @vcard.adr[:type].eql?(:work)
419
+ assert_equal "415.555.1234", @vcard.tel
420
+ end
421
+ end
41
422
 
423
+ # http://ufxtract.com/testsuite/hcard/hcard9.htm
424
+ describe 'extracting geo singular and paired values test' do
425
+ def self.before_all
426
+ @doc ||= test_fixture('hcard/hcard9.html')
427
+ @vcard ||= @@klass.parse(@doc)
428
+ end
429
+
430
+ setup do
431
+ @vcard = self.class.before_all
432
+ end
433
+
434
+ should 'find latitude value from single element' do
435
+ assert_equal '37.77', @vcard[0].geo[:latitude]
436
+ end
437
+
438
+ should 'extract latitude value from paired value' do
439
+ assert_equal '37.77', @vcard[1].geo[:latitude]
440
+ end
441
+ end
442
+
443
+ # http://ufxtract.com/testsuite/hcard/hcard99.htm
444
+ describe 'implied n optimization test' do
445
+ def self.before_all
446
+ @doc ||= test_fixture('hcard/hcard99.html')
447
+ @vcard ||= @@klass.parse(@doc)
448
+ end
449
+
450
+ setup do
451
+ @vcard = self.class.before_all
452
+ end
453
+
454
+ test 'The given-name value is implied from the fn value' do
455
+ assert_equal 'Ryan', @vcard[0].n[:given_name]
456
+ assert_equal 'Ryan', @vcard[1].n[:given_name]
457
+ assert_equal 'Ryan', @vcard[2].n[:given_name]
458
+ assert_equal 'Brian', @vcard[3].n[:given_name]
459
+ assert_equal 'Ryan', @vcard[4].n[:given_name]
460
+ assert_equal 'R', @vcard[5].n[:given_name]
461
+ assert_equal 'King', @vcard[6].n[:given_name]
462
+ end
463
+
464
+ test 'The family-name value is implied from the fn value' do
465
+ assert_equal 'King', @vcard[0].n[:family_name]
466
+ assert_equal 'King', @vcard[1].n[:family_name]
467
+ assert_equal 'King', @vcard[2].n[:family_name]
468
+ assert_equal 'Suda', @vcard[3].n[:family_name]
469
+ assert_equal 'King', @vcard[4].n[:family_name]
470
+ assert_equal 'King', @vcard[5].n[:family_name]
471
+ assert_equal 'R', @vcard[6].n[:family_name]
472
+ end
473
+
474
+ test 'The given name property should be missing' do
475
+ assert !@vcard[7].has_property?(:n)
476
+ assert !@vcard[8].has_property?(:n)
477
+ end
478
+
479
+ test 'The family name property should be missing' do
480
+ assert !@vcard[7].has_property?(:n)
481
+ assert !@vcard[8].has_property?(:n)
482
+ end
483
+ end
484
+
485
+ # http://ufxtract.com/testsuite/hcard/hcard17.htm
486
+ describe 'implied organization-name optimization test' do
487
+ def self.before_all
488
+ @doc ||= test_fixture('hcard/hcard17.html')
489
+ @vcard ||= @@klass.parse(@doc)
490
+ end
491
+
492
+ setup do
493
+ @vcard = self.class.before_all
494
+ end
495
+
496
+ test 'The organization-name value is implied from the org value' do
497
+ assert_equal 'World Wide Web Consortium', @vcard[0].org[:organization_name]
498
+ assert_equal 'World Wide Web Consortium', @vcard[1].org[:organization_name]
499
+ assert_equal 'World Wide Web Consortium', @vcard[2].org[:organization_name]
500
+ assert_equal 'World Wide Web Consortium', @vcard[3].org[:organization_name]
501
+ assert_equal 'World Wide Web Consortium', @vcard[4].org[:organization_name]
502
+ end
503
+
504
+ test 'The organization name value' do
505
+ assert_equal 'World Wide Web Consortium', @vcard[5].org[:organization_name]
506
+ assert_equal 'World Wide Web Consortium', @vcard[6].org[:organization_name]
507
+ end
508
+ end
42
509
 
43
510
  end