Class: Item

Inherits:
Object
  • Object
show all
Defined in:
lib/abelard/dir.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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
  timestamp_node = doc.find_first("/atom:entry/atom:published", NS) ||
                   doc.find_first("/item/pubDate")
  if timestamp_node
    @timestamp = Time.parse(timestamp_node.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

  author_node = doc.find_first("/atom:entry/atom:author/atom:name", NS) ||
                doc.find_first("/item/dc:creator", NS)
  if author_node
    @author = author_node.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

#authorObject

Returns the value of attribute author.



14
15
16
# File 'lib/abelard/dir.rb', line 14

def author
  @author
end

#docObject

Returns the value of attribute doc.



14
15
16
# File 'lib/abelard/dir.rb', line 14

def doc
  @doc
end

#fileObject

Returns the value of attribute file.



14
15
16
# File 'lib/abelard/dir.rb', line 14

def file
  @file
end

#statusObject

Returns the value of attribute status.



14
15
16
# File 'lib/abelard/dir.rb', line 14

def status
  @status
end

#timestampObject

Returns the value of attribute timestamp.



14
15
16
# File 'lib/abelard/dir.rb', line 14

def timestamp
  @timestamp
end

#titleObject

Returns the value of attribute title.



14
15
16
# File 'lib/abelard/dir.rb', line 14

def title
  @title
end

Instance Method Details

#saveObject



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