Class: Image

Inherits:
Object
  • Object
show all
Extended by:
Logging
Defined in:
lib/image.rb

Overview

An object of this class represents 1 picture file.

Constant Summary collapse

FORMATS =

string representations of supported image formats

{ :jpg  => 'image/jpeg',
:webp => 'image/webp',
:png  => 'image/png',
:gif  => 'image/gif',
:svg  => 'image/svg'}
@@log =
init_logger(STDOUT)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

init_logger, log_level=, log_target=

Methods included from File_Checking

file_check, #file_check, last_mime_type, magic_check, mime_check

Constructor Details

#initialize(path_url) ⇒ Image

Returns a new instance of Image.



56
57
58
59
60
61
# File 'lib/image.rb', line 56

def initialize(path_url)  
  @log = @@log
  @reference = path_url

  @log.debug('new Image instance : ' << @reference)
end

Instance Attribute Details

#referenceObject (readonly)

Returns the value of attribute reference.



33
34
35
# File 'lib/image.rb', line 33

def reference
  @reference
end

Class Method Details

.supported?(image, formats) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/image.rb', line 43

def self::supported?(image, formats)
  @log.debug('formats is ' << formats.to_s)
  msg = File_Checking::mime_check(image, FORMATS.values) 
  @@log.info(image.dup << ' ' << trl("is not supported, wrong mime-type") << ': ' << File_Checking.last_mime_type.to_s) if msg
  if !msg
    if !formats.include?(File_Checking.last_mime_type)
      msg = image.dup << ' ' << trl("is not in one of the requested file types") << ' (' << formats.join(', ') << ')'
      @@log.info(msg)     
    end
  end
  return msg
end