module HentryConsumer class HEntry < Element attr_accessor :name, :categories, :author, :content, :bookmark, :published_at, :summary alias_method :authors, :author def parse_elements(microformat) FormatClass.each do |letter| microformat.css(">*[class*=#{letter}-]").each do |attrs| attrs["class"].split.each do |klass| parse_element(attrs, klass) end end end 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 private def parse_element(microformat, klass) case klass when 'p-author' self.assign_value(symbolize_class(klass), HCard.new(microformat)) when 'p-category' self.categories ||= {} self.categories[microformat.text.gsub('\n', " ").strip] = microformat["href"] when 'e-content' self.content = parse_content(microformat) when'dt-published' self.published_at = microformat["datetime"] when "u-uid" self.bookmark = microformat["href"] else self.assign_value(symbolize_class(klass), microformat.text.gsub('\n', " ").strip) end end def parse_content(microformat) microformat.inner_html end end end