class Photoinfo

Attributes

collection[R]
contributor[R]
description[R]
info[R]
keywords[R]
photoid[R]
title[R]
uploadedon[R]
webpage[R]

Public Class Methods

new(photoid) click to toggle source
# File lib/photoinfo.rb, line 7
def initialize(photoid)
        @photoid = photoid.to_i
        # puts "Please input istockphoto id: "
        # @photoid = gets.chomp!.to_i
        # sample istockphoto id "21846754"
end

Public Instance Methods

isCollection() click to toggle source
# File lib/photoinfo.rb, line 36
def isCollection
        @collection = @webpage.xpath('//*[@id="file-subHeader"]//ul/li[1]').text.strip
end
isContributor() click to toggle source
# File lib/photoinfo.rb, line 26
def isContributor
        @contributor = @webpage.xpath('//*[@id="file-details-table"]//td[2]/ul/li/a[2]').text.strip
end
isDescription() click to toggle source
# File lib/photoinfo.rb, line 20
def isDescription
        a = @webpage.xpath('//*[@id="artist-description-container"]').text
        b = a.match (/(\n)(.+)(\n)(.+)/)
        @description = b[4].sub(/\s+/, "")
        "Description: #@description"
end
isKeywords() click to toggle source
# File lib/photoinfo.rb, line 29
def isKeywords
        @keywords = []
        @webpage.xpath('//*[@id="file-details-table"]//tr[2]/td[2]/a').each do |m|
                @keywords += [m.text]
        end
        @keywords = @keywords.join(", ")
end
isTitle() click to toggle source
# File lib/photoinfo.rb, line 17
def isTitle
        @title = @webpage.css('span#iSFileTitle').text.strip
end
isUploadedOn() click to toggle source
# File lib/photoinfo.rb, line 39
def isUploadedOn
        @uploadedon = @webpage.xpath('//*[@id="file-details-table"]//tr[6]/td[2]').text.strip
end
prepareToSave() click to toggle source
# File lib/photoinfo.rb, line 42
def prepareToSave
        read
        isTitle
        isDescription
        isContributor
        isKeywords
        isCollection
        isUploadedOn
end
read() click to toggle source
# File lib/photoinfo.rb, line 13
def read
        @webpage = Nokogiri::HTML(open("http://www.istockphoto.com/search/text/#@photoid").read)
        @webpage.encoding = 'utf-8'
end
save() click to toggle source
# File lib/photoinfo.rb, line 51
def save
        self.prepareToSave
        @info = {
                :title => @title, 
                :description => @description, 
                :contributor => @contributor, 
                :keywords => @keywords.to_s, 
                :collection => @collection, 
                :uploadedon => @uploadedon
        }
        output = File.new('istockphoto.yml', 'a+')
        output.puts YAML.dump(@info)
        output.close
end