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
15
# 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
  @published = parse_datetime(item.xpath(Dsl[@type][:item_published]).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



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

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



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

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