Class: FeedParser::FeedItem

Inherits:
Object
  • Object
show all
Defined in:
lib/feed_parser/feed_item.rb

Direct Known Subclasses

AtomItem, RssItem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ FeedItem

Returns a new instance of FeedItem.



7
8
9
10
11
12
13
14
# File 'lib/feed_parser/feed_item.rb', line 7

def initialize(item)
  @guid = item.xpath(Dsl[@type][:item_guid]).text
  @title = item.xpath(Dsl[@type][:item_title]).text
  @author = item.xpath(Dsl[@type][:item_author]).text
  @description = possible_html_content(item.xpath(Dsl[@type][:item_description]))
  @content = possible_html_content(item.xpath(Dsl[@type][:item_content]))
  self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/feed_parser/feed_item.rb', line 16

def method_missing(method_id)
  if self.instance_variables.map(&:to_sym).include?("@#{method_id}".to_sym)
    if FeedParser.fields_to_sanitize.include?(method_id)
      FeedParser.sanitizer.sanitize(self.instance_variable_get("@#{method_id}".to_sym))
    else
      self.instance_variable_get("@#{method_id}".to_sym)
    end
  else
    super
  end
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/feed_parser/feed_item.rb', line 5

def type
  @type
end

Instance Method Details

#as_jsonObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/feed_parser/feed_item.rb', line 28

def as_json
  {
    :guid => guid,
    :link => link,
    :title => title,
    :categories => categories,
    :author => author,
    :description => description,
    :content => content
  }
end