Sha256: 7ea3ab6bcef8e839be829d55da82948bc440a7523b45249b7ad8fb48e5949aed
Contents?: true
Size: 1.57 KB
Versions: 1
Compression:
Stored size: 1.57 KB
Contents
module HentryConsumer class HEntry < Element attr_accessor :name, :categories, :author, :content, :bookmark, :published_at, :summary alias_method :authors, :author def parse_elements FormatClass.each do |letter| @element.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.map(&:to_json), :content => self.content, :bookmark => self.bookmark, :published_at => self.published_at, :summary => self.summary } }] } end private def parse_element(microformat, klass) key, value = case klass when 'p-author' [symbolize_class(klass), HCard.new(microformat)] when 'p-category' self.categories ||= {} self.categories[microformat.text.gsub('\n', " ").strip] = microformat["href"] when 'e-content' [:content, parse_content(microformat)] when'dt-published' [:published_at, microformat["datetime"]] when "u-uid" [:bookmark, microformat['href']] else [symbolize_class(klass), microformat.text.gsub('\n', " ").strip] end assign_value(key, value) end def parse_content(microformat) microformat.inner_html end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hentry_consumer-0.3.1 | lib/hentry_consumer/h_entry.rb |