Class: Nokaya::Getter
- Inherits:
-
Object
- Object
- Nokaya::Getter
- Defined in:
- lib/nokaya/getter.rb
Instance Method Summary collapse
- #args ⇒ Object
- #get_image(img_link) ⇒ Object
- #get_link(page) ⇒ Object
-
#initialize(*args) ⇒ Getter
constructor
A new instance of Getter.
- #options ⇒ Object
- #parse_page ⇒ Object
- #photo_name ⇒ Object
- #save_image(path, img_link) ⇒ Object
- #type ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(*args) ⇒ Getter
Returns a new instance of Getter.
4 5 6 |
# File 'lib/nokaya/getter.rb', line 4 def initialize *args @args = OpenStruct.new options: args[0], type: args[1], url: args[2][0] end |
Instance Method Details
#args ⇒ Object
7 8 9 |
# File 'lib/nokaya/getter.rb', line 7 def args @args.inspect end |
#get_image(img_link) ⇒ Object
19 20 21 |
# File 'lib/nokaya/getter.rb', line 19 def get_image img_link open(img_link).read end |
#get_link(page) ⇒ Object
22 23 24 |
# File 'lib/nokaya/getter.rb', line 22 def get_link page page.xpath("//meta[@property='og:image']/@content").first end |
#options ⇒ Object
10 11 12 |
# File 'lib/nokaya/getter.rb', line 10 def @args. end |
#parse_page ⇒ Object
32 33 34 |
# File 'lib/nokaya/getter.rb', line 32 def parse_page Nokogiri::HTML get_page_content end |
#photo_name ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/nokaya/getter.rb', line 25 def photo_name unless @args.[:name] Dir.home + "/Downloads/#{@args.type.to_s}-#{Time.now.to_i}.jpg" else Dir.home + "/Downloads/#{@args.type.to_s}-#{@args.options[:name]}.jpg" end end |
#save_image(path, img_link) ⇒ Object
35 36 37 38 39 |
# File 'lib/nokaya/getter.rb', line 35 def save_image path, img_link f = File.new(path, "wb") f.puts(get_image img_link) f.close end |
#type ⇒ Object
13 14 15 |
# File 'lib/nokaya/getter.rb', line 13 def type @args.type end |
#url ⇒ Object
16 17 18 |
# File 'lib/nokaya/getter.rb', line 16 def url @args.url end |