Class: ImageQualityCheck::DetermineQuality

Inherits:
Object
  • Object
show all
Defined in:
lib/image_quality_check/determine_quality.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, column_name, tmp_file = nil) ⇒ DetermineQuality

Returns a new instance of DetermineQuality.



8
9
10
11
12
13
14
# File 'lib/image_quality_check/determine_quality.rb', line 8

def initialize(model, column_name, tmp_file = nil)
  @model = model
  @column_name = column_name
  @column = model.send(column_name)
  @messages = []
  @tmp_file = tmp_file
end

Class Method Details

.run(model, column_name, tmp_file = nil, &block) ⇒ Object



4
5
6
# File 'lib/image_quality_check/determine_quality.rb', line 4

def self.run(model, column_name, tmp_file = nil, &block)
  new(model, column_name, tmp_file).run(&block)
end

Instance Method Details

#run {|result| ... } ⇒ Object

Yields:

  • (result)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/image_quality_check/determine_quality.rb', line 16

def run(&block)
  unless @tmp_file
    @tmp_file = Tempfile.new(['image_quality'])
    unless read!(@tmp_file)
      result = {
        quality: 0,
        details: {},
        messages: [{ name: I18n.t('image_quality_check.not_found'), quality: 0 }]
      }
      yield(result) if block_given?
      return result
    end
  end

  @analyse_result = ImageQualityCheck.analyze(@tmp_file.path)
  result = {
    quality: determine_quality,
    details: @analyse_result,
    messages: @messages,
  }
  yield(result) if block_given?
  result
end