ratom 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ == 0.3.2 2008-04-09
2
+
3
+ * Add support for atom:category.
4
+ * Support extension attributes using the same mechanism as extension elements.
5
+
1
6
  == 0.3.1 2008-04-02
2
7
 
3
8
  * Bunch of fixes to the Atom::Pub classes to make them work like the Atom classes
@@ -66,6 +66,28 @@ module Atom # :nodoc:
66
66
  end
67
67
  end
68
68
 
69
+ # Represents a Category as defined by the Atom Syndication Format specification.
70
+ #
71
+ #
72
+ class Category
73
+ include Atom::Xml::Parseable
74
+ include SimpleExtensions
75
+ attribute :label, :scheme, :term
76
+
77
+ def initialize(o = nil)
78
+ case o
79
+ when XML::Reader
80
+ parse(o, :once => true)
81
+ when Hash
82
+ o.each do |k, v|
83
+ self.send("#{k.to_s}=", v)
84
+ end
85
+ end
86
+
87
+ yield(self) if block_given?
88
+ end
89
+ end
90
+
69
91
  # Represents a Person as defined by the Atom Syndication Format specification.
70
92
  #
71
93
  # A Person is used for all author and contributor attributes.
@@ -420,6 +442,7 @@ module Atom # :nodoc:
420
442
  element :source, :class => Source
421
443
  elements :links
422
444
  elements :authors, :contributors, :class => Person
445
+ elements :categories, :class => Category
423
446
 
424
447
  # Initialize an Entry.
425
448
  #
@@ -435,6 +458,7 @@ module Atom # :nodoc:
435
458
  @links = Links.new
436
459
  @authors = []
437
460
  @contributors = []
461
+ @categories = []
438
462
 
439
463
  case o
440
464
  when XML::Reader
@@ -52,17 +52,9 @@ module Atom
52
52
  end
53
53
  end
54
54
 
55
- class Category
56
- include Atom::Xml::Parseable
57
- def initialize(o)
58
- o.read
59
- parse(o, :once => true)
60
- end
61
- end
62
-
63
55
  class Categories < DelegateClass(Array)
64
56
  include Atom::Xml::Parseable
65
- elements :categories, :class => Category
57
+ elements :categories, :class => Atom::Category
66
58
 
67
59
  def initialize(o)
68
60
  super([])
@@ -2,7 +2,7 @@ module Atom #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -44,6 +44,8 @@ module Atom
44
44
  if attributes.include?(xml.name)
45
45
  # Support attribute names with namespace prefixes
46
46
  self.send("#{xml.name.sub(/:/, '_')}=", xml.value)
47
+ elsif self.respond_to?(:simple_extensions)
48
+ self[xml.namespace_uri, xml.local_name] << xml.value
47
49
  end
48
50
  end
49
51
  elsif self.respond_to?(:simple_extensions)
@@ -271,6 +271,48 @@ describe Atom do
271
271
  it "should have content" do
272
272
  @entry.content.should_not be_nil
273
273
  end
274
+
275
+ it "should have 2 categories" do
276
+ @entry.should have(2).categories
277
+ end
278
+ end
279
+
280
+ describe Atom::Category do
281
+ describe 'atom category' do
282
+ before(:each) do
283
+ @category = @feed.entries.first.categories.first
284
+ end
285
+
286
+ it "should have a term" do
287
+ @category.term.should == "atom"
288
+ end
289
+
290
+ it "should have a scheme" do
291
+ @category.scheme.should == "http://example.org"
292
+ end
293
+
294
+ it "should have a label" do
295
+ @category.label.should == "Atom"
296
+ end
297
+ end
298
+
299
+ describe 'draft category' do
300
+ before(:each) do
301
+ @category = @feed.entries.first.categories.last
302
+ end
303
+
304
+ it "should have a term" do
305
+ @category.term.should == "drafts"
306
+ end
307
+
308
+ it "should have a scheme" do
309
+ @category.scheme.should == "http://example2.org"
310
+ end
311
+
312
+ it "should have a label" do
313
+ @category.label.should == "Drafts"
314
+ end
315
+ end
274
316
  end
275
317
 
276
318
  describe Atom::Link do
@@ -859,8 +901,6 @@ describe Atom do
859
901
  describe 'pagination using each_entries' do
860
902
  before(:each) do
861
903
  @feed = Atom::Feed.load_feed(File.open('spec/paging/first_paged_feed.atom'))
862
-
863
-
864
904
  end
865
905
 
866
906
  it "should paginate through each entry" do
@@ -930,6 +970,10 @@ describe Atom do
930
970
  @entry["http://example2.org/example2", 'simple1'].should == ['Simple Entry Value (NS2)']
931
971
  end
932
972
 
973
+ it "should load simple extension attribute on a category" do
974
+ @entry.categories.first["http://example.org/example", "attribute"].first.should == "extension"
975
+ end
976
+
933
977
  it "should read an extension with the same local name as an Atom element" do
934
978
  @feed['http://example.org/example', 'title'].should == ['Extension Title']
935
979
  end
@@ -1064,4 +1108,25 @@ describe Atom do
1064
1108
  Atom::Content::Html.new("&nbsp;").to_xml.to_s.should == "<content type=\"html\">&amp;nbsp;</content>"
1065
1109
  end
1066
1110
  end
1111
+
1112
+ describe 'Atom::Category initializer' do
1113
+ it "should create a empty category" do
1114
+ lambda { Atom::Category.new }.should_not raise_error
1115
+ end
1116
+
1117
+ it "should create from a hash" do
1118
+ category = Atom::Category.new(:term => 'term', :scheme => 'scheme', :label => 'label')
1119
+ category.term.should == 'term'
1120
+ category.scheme.should == 'scheme'
1121
+ category.label.should == 'label'
1122
+ end
1123
+
1124
+ it "should create from a block" do
1125
+ category = Atom::Category.new do |cat|
1126
+ cat.term = 'term'
1127
+ end
1128
+
1129
+ category.term.should == 'term'
1130
+ end
1131
+ end
1067
1132
  end
@@ -35,6 +35,8 @@
35
35
  <contributor>
36
36
  <name>Joe Gregorio</name>
37
37
  </contributor>
38
+ <category term="atom" scheme="http://example.org" label="Atom" />
39
+ <category term="drafts" scheme="http://example2.org" label="Drafts" />
38
40
  <content type="xhtml" xml:lang="en"
39
41
  xml:base="http://diveintomark.org/">
40
42
  <div xmlns="http://www.w3.org/1999/xhtml">
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ratom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peerworks
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-04-02 00:00:00 +10:30
12
+ date: 2008-04-09 00:00:00 +09:30
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency