Class: HEntry

Inherits:
Microformat show all
Defined in:
lib/mofo/hentry.rb

Instance Method Summary collapse

Methods inherited from Microformat

#method_missing

Methods included from Microformat::Base

#find, #find_in_children, #timeout=

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Microformat

Instance Method Details

#atom_idObject



18
19
20
# File 'lib/mofo/hentry.rb', line 18

def atom_id
  "<id>tag:#{@domain},2008-01-22:#{Digest::MD5.hexdigest(entry_content)}</id>"
end


22
23
24
# File 'lib/mofo/hentry.rb', line 22

def atom_link
  %(<link type="text/html" href="http://#{@domain}#{@bookmark}" rel="alternate"/>)
end

#to_atom(property = nil, value = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mofo/hentry.rb', line 26

def to_atom(property = nil, value = nil)
  require 'digest/md5'
  require 'erb'

  if property
    value ||= instance_variable_get("@#{property}")
    return value ? ("<#{property}>%s</#{property}>" % value) : nil
  end

  entity = <<-atom_entity
<entry>
  #{atom_id}
  #{atom_link}
  #{to_atom :title, @entry_title}
  <content type="html">#{ERB::Util.h @entry_content}</content>
  #{to_atom :updated, @updated.try(:xmlschema)}
  #{to_atom :published, @updated.try(:xmlschema)}
  <author>
    #{to_atom :name, @author.try(:fn)}
    #{to_atom :email, @author.try(:email)}
  </author>
</entry>
  atom_entity
end