class Profound::Input
Constants
- Keywords
- Qualifiers
Public Class Methods
new(source, options = {})
click to toggle source
# File lib/profound.rb, line 38 def initialize(source, options = {}) @source = source || [Qualifiers.sample, Keywords.sample].join(" ") @options = options end
Public Instance Methods
download()
click to toggle source
# File lib/profound.rb, line 47 def download url = search response = Net::HTTP.get_response(URI.parse(url)) tmp = Tempfile.new("profound") tmp.write(response.body) tmp.rewind tmp.path end
path()
click to toggle source
# File lib/profound.rb, line 43 def path File.exists?(@source) ? @source : download end
search()
click to toggle source
# File lib/profound.rb, line 58 def search fetcher = Fotofetch::Fetch.new links = fetcher.fetch_links(@source, 15, @options[:width], @options[:height]) raise EmptyQueryResult, "Could not find images matching #{@source.inspect}" if links.empty? links.values.sample end