Class: Omnom::Source::Reddit::Images

Inherits:
Default show all
Defined in:
lib/omnom/source/reddit/images.rb

Instance Attribute Summary

Attributes inherited from Base

#config, #feed_key, #key, #options, #settings, #source_id

Instance Method Summary collapse

Methods inherited from Default

#after_initialize, #get_raw_posts

Methods inherited from Base

#after_initialize, config, configure, cron, every, feed_url, full_key, guid_namespace, icon, icon_from_url, inherited, #initialize, key, required_config, required_options, #update, url

Methods included from ParserMethods

#html_to_text

Constructor Details

This class inherits a constructor from Omnom::Source::Base

Instance Method Details

#get_imgur_images(url) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/omnom/source/reddit/images.rb', line 22

def get_imgur_images(url)
  page = @agent.get(url)
  return nil if page.blank?
  image_nodes = page.search('.panel .image a > img')
  image_nodes.collect do |image_node|
    {
      page_url: url,
      image_url: image_node.attr('src') || image_node.attr('data-src')
    }
  end
end

#post_attributes(node) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/omnom/source/reddit/images.rb', line 7

def post_attributes(node)
  attributes = super
  if attributes[:url] =~ /(?:.bmp|.gif|.jpeg|.jpg|.png|.tiff)$/
    images = [{
      page_url: attributes[:url],
      image_url: attributes[:url]
    }]
  elsif attributes[:url] =~ /http:\/\/imgur.com\/\w{3,}$/ || attributes[:url] =~ /http:\/\/imgur.com\/a\/\w{3,}$/
    images = get_imgur_images(attributes[:url])
  end
  return nil unless images
  attributes[:other][:images] = images
  attributes
end