Class: MetaWeblog::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/metaweblog/post.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Post

Returns a new instance of Post.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/metaweblog/post.rb', line 10

def initialize(*args)
  @data = {}

  if args.length == 1 && args.last.is_a?(Hash)
    h = args.last
    data = self.class.members.map { |m| (h[m] || h[m.to_s]) }
  else
    data = args
  end
  self.class.members.each_with_index do |member, i|
    self.__send__ "#{member}=", data[i] if data[i]
  end
end

Class Method Details

.membersObject



6
7
8
# File 'lib/metaweblog/post.rb', line 6

def self.members
  [:title, :link, :description, :pubDate]
end

Instance Method Details

#[](m) ⇒ Object



24
25
26
# File 'lib/metaweblog/post.rb', line 24

def [](m)
  @data[m]
end

#pub_date=(pub_date) ⇒ Object Also known as: pubDate=



42
43
44
45
46
47
48
49
# File 'lib/metaweblog/post.rb', line 42

def pub_date=(pub_date)
  @data[:pubDate] = case pub_date
    when String then Time.parse(pub_date)
    when Time, DateTime then pub_date
    else
      raise ArgumentError, "The argument is not String, Time and DateTime."
    end
end

#to_hObject



28
29
30
# File 'lib/metaweblog/post.rb', line 28

def to_h
  @data.dup
end