Class: OmgImage::Processor
- Inherits:
-
Object
- Object
- OmgImage::Processor
- Defined in:
- lib/omg_image/processor.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #cached_or_new(regenerate: false) ⇒ Object
- #generate(cache: true) ⇒ Object
-
#initialize(template, options) ⇒ Processor
constructor
A new instance of Processor.
- #with_screenshot(&block) ⇒ Object
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, ) template.downcase! ||= {} [:size] ||= '800,400' [:key] ||= .to_s template = "#{template}.html.erb" unless template.ends_with?(".html.erb") @template = template @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/omg_image/processor.rb', line 3 def @options end |
#template ⇒ Object (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 |