module HentryConsumer class HEntry < Element attr_accessor :name, :categories, :author, :content, :bookmark, :published_at, :summary alias_method :authors, :author # overrides Element#parse_microformat def parse_microformat(element, c) case c when "p-author" then parse_author(element) when "p-category" then parse_category(element) when "e-content" then parse_content(element) when "dt-published" then parse_published(element) when "u-uid" then parse_uid(element) else parse_general(element, c) end end def parse_author(element) assign_value :author, HCard.new(element.children) end def parse_category(element) self.categories ||= {} self.categories[element.text.gsub("\n", " ").strip] = element["href"] end def parse_content(element) assign_value :content, element.inner_html end def parse_published(element) assign_value :published_at, element["datetime"] end def parse_uid(element) assign_value :bookmark, element["href"] end def parse_general(element, c) assign_value symbolize_class(c), element.text end def to_json(*a) {:items => [{ :type => ["h-entry"], :properties => { :name => self.name, :categories => self.categories, :author => self.author, :content => self.content, :bookmark => self.bookmark, :published_at => self.published_at, :summary => self.summary } }] }.to_json(a) end end end