Class: Nokaya::Getter

Inherits:
Object
  • Object
show all
Defined in:
lib/nokaya/getter.rb

Instance Method Summary collapse

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

#argsObject



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


22
23
24
# File 'lib/nokaya/getter.rb', line 22

def get_link page
  page.xpath("//meta[@property='og:image']/@content").first
end

#optionsObject



10
11
12
# File 'lib/nokaya/getter.rb', line 10

def options
  @args.options
end

#parse_pageObject



32
33
34
# File 'lib/nokaya/getter.rb', line 32

def parse_page
  Nokogiri::HTML get_page_content
end

#photo_nameObject



25
26
27
28
29
30
31
# File 'lib/nokaya/getter.rb', line 25

def photo_name
  unless @args.options[: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

#typeObject



13
14
15
# File 'lib/nokaya/getter.rb', line 13

def type
  @args.type
end

#urlObject



16
17
18
# File 'lib/nokaya/getter.rb', line 16

def url
  @args.url
end