Sha256: 1251bc40043a4b947c80b8d84387c8cf064ec961194e4c217fa783b6a0725a05

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

module Writer
  module Fetcher
    module Microdata
      class ArticleSmall
        attr_accessor :source

        def initialize the_source
          self.source = the_source
        end

        def hash
          @attributes = @source.attributes
          resp = {
            "type" => [@source._type],
            "properties" => {
              "additionalType" => [
                @attributes[:additionalType]
              ],
              "Item#id" => [
                @attributes[:id]
              ],
              "articleBody" => [
                @attributes[:articleBody]
              ],
              "author" => [
                @attributes[:author].to.hash
              ],
              "Item#viewer" => [
                @attributes[:viewer].to.hash
              ],
              "UserComments" => [
              ],
              "dateCreated" => [
                @attributes[:dateCreated]
              ],
              "provider" => @attributes[:provider],
              "url" => [
                @attributes[:url]
              ]
            }
          }
          @attributes[:comments].each do |c|
            resp["properties"]["UserComments"].push c.to.hash
          end

          resp["properties"].keys.each do |att|
            if resp["properties"]["#{att}"] == [nil]
              resp["properties"].delete "#{att}"
            end
          end
          resp
          
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fetcher-microdata-0.0.13 lib/writer/fetcher-microdata/article_small.rb