Class: Camdram::Image

Inherits:
Base
  • Object
show all
Includes:
API, Refreshable
Defined in:
lib/camdram/image.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#id

Instance Method Summary collapse

Methods included from Refreshable

#refresh!

Methods inherited from Base

#make_orphan

Constructor Details

#initialize(*args) ⇒ Camdram::Image

Instantiate a new Image object from a JSON hash

Parameters:

  • options (Hash)

    A single JSON hash with symbolized keys.


18
19
20
21
22
# File 'lib/camdram/image.rb', line 18

def initialize(*args)
  super(*args)
  @created_at = DateTime.parse(@created_at) unless @created_at.nil?
  @type = MIME::Types[@type].first unless @type.nil?
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at


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

def created_at
  @created_at
end

#extensionObject

Returns the value of attribute extension


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

def extension
  @extension
end

#filenameObject

Returns the value of attribute filename


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

def filename
  @filename
end

#heightObject

Returns the value of attribute height


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

def height
  @height
end

#typeObject

Returns the value of attribute type


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

def type
  @type
end

#widthObject

Returns the value of attribute width


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

def width
  @width
end

Instance Method Details

#infoHash

Return a hash of the image's attributes

Returns:

  • (Hash)

    Hash with symbolized keys.


27
28
29
30
31
32
33
34
35
36
37
# File 'lib/camdram/image.rb', line 27

def info
  {
    id: id,
    filename: filename,
    created_at: created_at,
    width: width,
    height: height,
    extension: extension,
    type: type,
  }
end

#urlString

Return the image URL

Returns:

  • (String)

    The image URL.


42
43
44
# File 'lib/camdram/image.rb', line 42

def url
  "/media/cache/preview/#{filename}"
end