Class: HbExporter::Pin

Inherits:
Object
  • Object
show all
Defined in:
lib/hb_exporter/pin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, opt = {}) ⇒ Pin

Returns a new instance of Pin.



8
9
10
11
# File 'lib/hb_exporter/pin.rb', line 8

def initialize(key, opt={})
  @key  = key
  @data = opt[:data]
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



6
7
8
# File 'lib/hb_exporter/pin.rb', line 6

def data
  @data
end

#keyObject

Returns the value of attribute key.



6
7
8
# File 'lib/hb_exporter/pin.rb', line 6

def key
  @key
end

Instance Method Details

#export(path: '') ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hb_exporter/pin.rb', line 25

def export path: ''
  file_path = File.join(path, export_file_name)
  return true if File.size?(file_path)

  Tempfile.create(export_file_name) do |tmpfile|
    tmpfile << HTTParty.get(image_url)
    tmpfile.flush
    FileUtils.cp tmpfile, file_path
  end
  true
end

#export_file_nameObject



38
39
40
# File 'lib/hb_exporter/pin.rb', line 38

def export_file_name
  [key, suffix].join ?.
end

#image_urlObject



19
20
21
22
# File 'lib/hb_exporter/pin.rb', line 19

def image_url
  return nil unless key
  @image_url ||= "http://img.hb.aicdn.com/" << key
end

#suffixObject



43
44
45
# File 'lib/hb_exporter/pin.rb', line 43

def suffix
  data['file']['type'].split('/').last
end

#to_sObject



14
15
16
# File 'lib/hb_exporter/pin.rb', line 14

def to_s
  "#<Pin #{key} #{image_url}>"
end