Class: HbExporter::Pin
- Inherits:
-
Object
- Object
- HbExporter::Pin
- Defined in:
- lib/hb_exporter/pin.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
- #export(path: '') ⇒ Object
- #export_file_name ⇒ Object
- #image_url ⇒ Object
-
#initialize(key, opt = {}) ⇒ Pin
constructor
A new instance of Pin.
- #suffix ⇒ Object
- #to_s ⇒ Object
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
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/hb_exporter/pin.rb', line 6 def data @data end |
#key ⇒ Object
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_name ⇒ Object
38 39 40 |
# File 'lib/hb_exporter/pin.rb', line 38 def export_file_name [key, suffix].join ?. end |
#image_url ⇒ Object
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 |
#suffix ⇒ Object
43 44 45 |
# File 'lib/hb_exporter/pin.rb', line 43 def suffix data['file']['type'].split('/').last end |
#to_s ⇒ Object
14 15 16 |
# File 'lib/hb_exporter/pin.rb', line 14 def to_s "#<Pin #{key} #{image_url}>" end |