Class: WikiOnThisDay::Printer
- Inherits:
-
Object
- Object
- WikiOnThisDay::Printer
- Defined in:
- lib/wiki_on_this_day/printer.rb
Overview
require ‘catpix’
Instance Attribute Summary collapse
-
#events_hash ⇒ Object
readonly
Returns the value of attribute events_hash.
-
#html_doc ⇒ Object
readonly
Returns the value of attribute html_doc.
Instance Method Summary collapse
-
#initialize(html_doc, events_hash) ⇒ Printer
constructor
A new instance of Printer.
-
#print ⇒ Object
def on_this_day_image open(‘https:’ + self.html_doc.css(‘div#mp-otd-img img’).attribute(‘src’).value) { |file| image_of_the_day = Tempfile.new(“image_of_the_day”) image_of_the_day << file.read image_of_the_day.rewind Catpix::print_image image_of_the_day.path, :limit_x => 0.5, :limit_y => 0, :center_x => true, :center_y => false, :bg => “white”, :bg_fill => true, :resolution => “high” image_of_the_day.close } end.
Constructor Details
#initialize(html_doc, events_hash) ⇒ Printer
Returns a new instance of Printer.
7 8 9 10 |
# File 'lib/wiki_on_this_day/printer.rb', line 7 def initialize(html_doc, events_hash) @html_doc = html_doc @events_hash = events_hash end |
Instance Attribute Details
#events_hash ⇒ Object (readonly)
Returns the value of attribute events_hash.
5 6 7 |
# File 'lib/wiki_on_this_day/printer.rb', line 5 def events_hash @events_hash end |
#html_doc ⇒ Object (readonly)
Returns the value of attribute html_doc.
5 6 7 |
# File 'lib/wiki_on_this_day/printer.rb', line 5 def html_doc @html_doc end |
Instance Method Details
#print ⇒ Object
def on_this_day_image
open('https:' + self.html_doc.css('div#mp-otd-img img').attribute('src').value) { |file|
image_of_the_day = Tempfile.new("image_of_the_day")
image_of_the_day << file.read
image_of_the_day.rewind
Catpix::print_image image_of_the_day.path,
:limit_x => 0.5,
:limit_y => 0,
:center_x => true,
:center_y => false,
:bg => "white",
:bg_fill => true,
:resolution => "high"
image_of_the_day.close
}
end
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/wiki_on_this_day/printer.rb', line 29 def print @events_hash.each do |key, value| puts value[:year] abstract = value [:text] if /\W\(pictured\)/.match(abstract) puts abstract.gsub(/\W\(pictured\)/, '') else puts abstract end end end |