Class: FeedParser::FeedItem
- Inherits:
-
Object
- Object
- FeedParser::FeedItem
- Defined in:
- lib/feed_parser/feed_item.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(item) ⇒ FeedItem
constructor
A new instance of FeedItem.
- #method_missing(method_id) ⇒ Object
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
#type ⇒ Object (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_json ⇒ Object
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., :description => self.description, :content => self.content } end |