Class: Mashfeed::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/mashfeed/entry.rb

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ Entry

Returns a new instance of Entry.



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/mashfeed/entry.rb', line 3

def initialize(data=nil)
  @data_ = {}
  return if data.nil?
  if data.is_a?(Hash)
    data.each_pair do |key, value|
      @data_[key.to_s] = value
    end
  else
    [:title, :link, :description, :time, :author, :comments, :guid, :enclosure, :source, :categories].each do |field|
      @data_[field.to_s] = data.send(field) if data.respond_to?(field)
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *argv) ⇒ Object



17
18
19
20
21
# File 'lib/mashfeed/entry.rb', line 17

def method_missing(name, *argv)
  @data_ ||= {}
  name_ = (/^(.+)=$/.match(name.to_s)).to_a[1]
  name_.nil? ? @data_[name.to_s] : (@data_[name_]=argv.first)
end