Class: Item
- Inherits:
-
Object
- Object
- Item
- Defined in:
- lib/abelard/dir.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#file ⇒ Object
Returns the value of attribute file.
-
#status ⇒ Object
Returns the value of attribute status.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(xml, filename) ⇒ Item
constructor
A new instance of Item.
- #save ⇒ Object
Constructor Details
#initialize(xml, filename) ⇒ Item
Returns a new instance of Item.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/abelard/dir.rb', line 15 def initialize(xml, filename) @doc = xml @file = filename = doc.find_first("/atom:entry/atom:published", NS) || doc.find_first("/item/pubDate") if @timestamp = Time.parse(.content) else @timestamp = Time.new(0) end title_node = doc.find_first("/atom:entry/atom:title", NS) || doc.find_first("/item/title") if title_node @title = title_node.content else @title = "Post" end = doc.find_first("/atom:entry/atom:author/atom:name", NS) || doc.find_first("/item/dc:creator", NS) if @author = .content else @author = 'abelard' end @status = :published status_node = doc.find_first("/item/wp:status", NS) if status_node $stderr.puts("raw status #{status_node.content}") if status_node.content == "trash" @status = :trash elsif status_node.content == "draft" @status = :draft end end draft_node = doc.find_first("/atom:entry/app:control/app:draft", NS) if draft_node if draft_node.content == "yes" @status = :draft end end end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
14 15 16 |
# File 'lib/abelard/dir.rb', line 14 def @author end |
#doc ⇒ Object
Returns the value of attribute doc.
14 15 16 |
# File 'lib/abelard/dir.rb', line 14 def doc @doc end |
#file ⇒ Object
Returns the value of attribute file.
14 15 16 |
# File 'lib/abelard/dir.rb', line 14 def file @file end |
#status ⇒ Object
Returns the value of attribute status.
14 15 16 |
# File 'lib/abelard/dir.rb', line 14 def status @status end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
14 15 16 |
# File 'lib/abelard/dir.rb', line 14 def @timestamp end |
#title ⇒ Object
Returns the value of attribute title.
14 15 16 |
# File 'lib/abelard/dir.rb', line 14 def title @title end |
Instance Method Details
#save ⇒ Object
61 62 63 64 |
# File 'lib/abelard/dir.rb', line 61 def save puts("writing #{file}") doc.save(file, :indent => true, :encoding => LibXML::XML::Encoding::UTF_8) end |