Class: Colorant::Processer

Inherits:
Object
  • Object
show all
Defined in:
lib/colorant/processer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}) ⇒ Processer

Returns a new instance of Processer.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/colorant/processer.rb', line 5

def initialize(file, options = {})
  begin
    File.open(file)
  rescue=>e
    raise ArgumentError.new "#{file} does not exist or is not a valid image file"
  end
  @file = file
  @colors = options[:colors] ? options[:colors].to_i : 8
  @depth = options[:depth] ? options[:depth].to_i : 16
  @reporter_options = {:reporter => options[:reporter],
                       :extended => options[:extended]}
  @data = []
end

Instance Attribute Details

#colorsObject (readonly)

Returns the value of attribute colors.



3
4
5
# File 'lib/colorant/processer.rb', line 3

def colors
  @colors
end

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/colorant/processer.rb', line 3

def data
  @data
end

#depthObject (readonly)

Returns the value of attribute depth.



3
4
5
# File 'lib/colorant/processer.rb', line 3

def depth
  @depth
end

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/colorant/processer.rb', line 3

def file
  @file
end

Class Method Details

.process(*args) ⇒ Object



26
27
28
29
# File 'lib/colorant/processer.rb', line 26

def process(*args)
  instance = new(*args)
  instance.process!
end

Instance Method Details

#process!Object



19
20
21
22
23
# File 'lib/colorant/processer.rb', line 19

def process!
  raw_data = `convert #{file} -gravity Center -crop 80x60% +repage -format %c -colors #{colors} -depth #{depth} histogram:info:- | sort -r -k 1`
  @data = Parser.parse(raw_data)
  Reporter.report(@data, @reporter_options)
end