Class: ScaleDown::Info

Inherits:
Object
  • Object
show all
Defined in:
lib/scale_down/info.rb

Overview

Returns a json object with the height, width attributes

Instance Method Summary collapse

Constructor Details

#initialize(relative_path) ⇒ Info

Returns a new instance of Info.



6
7
8
9
10
11
12
13
14
15
# File 'lib/scale_down/info.rb', line 6

def initialize(relative_path)
  path = [ScaleDown.public_folder, relative_path].join("/")
  if File.exists?(path)
    GC.start
    @image_list = Magick::Image.read(path)
    @image = @image_list.first
  else
    @missing = true
  end
end

Instance Method Details

#hashObject



21
22
23
24
25
26
27
28
# File 'lib/scale_down/info.rb', line 21

def hash
  {
    height: @image.rows,
    width: @image.columns,
    # is this an animated GIF or other file
    animated: @image_list.size > 1
  }
end

#missing?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/scale_down/info.rb', line 17

def missing?
  @missing == true
end

#to_jsonObject



30
31
32
# File 'lib/scale_down/info.rb', line 30

def to_json
  JSON hash
end