Class: OmgImage::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/omg_image/processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, options) ⇒ Processor

Returns a new instance of Processor.



5
6
7
8
9
10
11
12
13
# File 'lib/omg_image/processor.rb', line 5

def initialize(template, options)
  template.downcase!
  options        ||= {}
  options[:size] ||= '800,400'
  options[:key]  ||= options.to_s
  template         = "#{template}.html.erb" unless template.ends_with?(".html.erb")
  @template        = template
  @options         = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/omg_image/processor.rb', line 3

def options
  @options
end

#templateObject (readonly)

Returns the value of attribute template.



3
4
5
# File 'lib/omg_image/processor.rb', line 3

def template
  @template
end

Instance Method Details

#cached_or_new(regenerate: false) ⇒ Object



15
16
17
18
# File 'lib/omg_image/processor.rb', line 15

def cached_or_new(regenerate: false)
  reset_cache if regenerate
  cached&.file || generate&.file
end

#generate(cache: true) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/omg_image/processor.rb', line 20

def generate(cache: true)
  output = create_screenshot
  if cache
    image = save_to_cache(output)
    output&.close
    image
  else
    output
  end
end

#with_screenshot(&block) ⇒ Object



31
32
33
# File 'lib/omg_image/processor.rb', line 31

def with_screenshot(&block)
  create_screenshot(&block)
end