37 lines
953 B
Ruby
37 lines
953 B
Ruby
# Contains data of a single ADN post.
|
|
class PostData
|
|
attr_accessor :post_id
|
|
attr_accessor :created_at
|
|
|
|
def initialize
|
|
@post_id = 1
|
|
@created_at = Date.new(1970,1,1)
|
|
end
|
|
|
|
# in: array of posts
|
|
# returns: class instance with the topmost (= most recent) post from the array
|
|
# assumes: the array of posts is sorted in reverse alphabetical order.
|
|
def self.most_recent_post(post_array)
|
|
post_id = 1
|
|
created_at = Time.new(1970,1,1)
|
|
post = PostData.new
|
|
post_array.each do |line|
|
|
line.each do |elem|
|
|
puts "--- post_data.line_elem: " + elem.to_s
|
|
case elem[0]
|
|
when "id"
|
|
post_id = elem[1].to_i
|
|
when "created_at"
|
|
created_at = Time.parse(elem[1])
|
|
else
|
|
# (currently) not of interest
|
|
end
|
|
if post_id > post.post_id then
|
|
post.post_id = post_id
|
|
post.created_at = created_at
|
|
end
|
|
end
|
|
end
|
|
post
|
|
end
|
|
end
|