class ReadIt::Post
Public Class Methods
new(data)
click to toggle source
# File lib/read_it/post.rb, line 9 def initialize data @data = data end
parse(response)
click to toggle source
# File lib/read_it/post.rb, line 3 def self.parse response response = JSON.parse response.body posts = response.fetch("data", {}).fetch "children", [] posts.map { |post| new post["data"] } end
Public Instance Methods
image()
click to toggle source
# File lib/read_it/post.rb, line 17 def image url if image? end
image?()
click to toggle source
# File lib/read_it/post.rb, line 13 def image? image_types.include? url.split('.').last.downcase end
method_missing(name, *args, &block)
click to toggle source
# File lib/read_it/post.rb, line 25 def method_missing name, *args, &block @data[name.to_s] end
nsfw?()
click to toggle source
# File lib/read_it/post.rb, line 21 def nsfw? over_18 end
Private Instance Methods
image_types()
click to toggle source
# File lib/read_it/post.rb, line 31 def image_types %w(png jpg jpeg gif) end