Class: Gyazo::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/gyazo/image.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(upload_data) ⇒ Image

Returns a new instance of Image.



4
5
6
# File 'lib/gyazo/image.rb', line 4

def initialize(upload_data)
  @file = upload_data[:tempfile]
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/gyazo/image.rb', line 3

def file
  @file
end

Class Method Details

.adapter=(sym_or_klass) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/gyazo/image.rb', line 34

def adapter=(sym_or_klass)
  if sym_or_klass.kind_of?(Symbol)
    @adapter = adapter_map[sym_or_klass]
  else
    @adapter = sym_or_klass
  end
end

.adapter_classObject



30
31
32
# File 'lib/gyazo/image.rb', line 30

def adapter_class
  @adapter || ::Gyazo::UploadAdapters::Fog
end

Instance Method Details

#dataObject



16
17
18
# File 'lib/gyazo/image.rb', line 16

def data
  @data ||= @file.read
end

#nameObject



20
21
22
# File 'lib/gyazo/image.rb', line 20

def name
  @name ||= Digest::MD5.hexdigest(data).to_s + ".jpg"
end

#uploadObject



8
9
10
# File 'lib/gyazo/image.rb', line 8

def upload
  @url = self.adapter.upload
end

#urlObject



12
13
14
# File 'lib/gyazo/image.rb', line 12

def url
  @url
end