Class: HEntry

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

Class Method Summary collapse

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

Class Method Details

.build_class(microformat) ⇒ Object



65
66
67
68
69
# File 'lib/mofo/hentry.rb', line 65

def self.build_class(microformat)
  hentry = super(microformat)
  hentry.add_in_parent_hcard if hentry.missing_author?
  hentry
end

.find_in_parent_hcardObject

Raises:



71
72
73
74
75
# File 'lib/mofo/hentry.rb', line 71

def self.find_in_parent_hcard
  author = HCard.find(:text => (@doc/"//.hentry/..//address.vcard").to_s)
  raise InvalidMicroformat if @options[:strict] && author.empty?
  prepare_value(author)
end

Instance Method Details

#add_in_parent_hcardObject



54
55
56
57
# File 'lib/mofo/hentry.rb', line 54

def add_in_parent_hcard
  @properties << 'author'
  @author = in_parent_hcard
end

#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

#in_parent_hcardObject

Per spec: if the entry author is missing find the nearest in parent <address> element(s) with class name author



61
62
63
# File 'lib/mofo/hentry.rb', line 61

def in_parent_hcard
  @in_parent_hcard ||= self.class.find_in_parent_hcard
end

#missing_author?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/mofo/hentry.rb', line 50

def missing_author?
  @author.nil?
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
# 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}
  #{to_atom :updated, @updated.try(:xmlschema)}
  <author>
    #{to_atom :name, @author.try(:fn)}
    #{to_atom :email, @author.try(:email)}
  </author>
  <content type="html">#{ERB::Util.h @entry_content}</content>
</entry>
  atom_entity
end