Class: Writer::Fetcher::Microdata::ArticleSmall

Inherits:
Object
  • Object
show all
Defined in:
lib/writer/fetcher-microdata/article_small.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(the_source) ⇒ ArticleSmall

Returns a new instance of ArticleSmall.



7
8
9
# File 'lib/writer/fetcher-microdata/article_small.rb', line 7

def initialize the_source
  self.source = the_source
end

Instance Attribute Details

#sourceObject

Returns the value of attribute source.



5
6
7
# File 'lib/writer/fetcher-microdata/article_small.rb', line 5

def source
  @source
end

Instance Method Details

#hashObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/writer/fetcher-microdata/article_small.rb', line 11

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