Class: PrintMap::Worker
- Inherits:
-
Object
- Object
- PrintMap::Worker
- Defined in:
- lib/print_map/worker.rb
Instance Attribute Summary collapse
-
#current_job ⇒ Object
readonly
Returns the value of attribute current_job.
-
#legend_images_collector ⇒ Object
readonly
Returns the value of attribute legend_images_collector.
-
#map_exporter ⇒ Object
readonly
Returns the value of attribute map_exporter.
-
#pdf_generator ⇒ Object
readonly
Returns the value of attribute pdf_generator.
Instance Method Summary collapse
- #collect_legend_images ⇒ Object
- #create_composite_map_image ⇒ Object
- #do_job(job) ⇒ Object
- #generate_pdf(map_image, legend_images) ⇒ Object
-
#initialize(config = {}) ⇒ Worker
constructor
A new instance of Worker.
Constructor Details
#initialize(config = {}) ⇒ Worker
Returns a new instance of Worker.
12 13 14 15 16 |
# File 'lib/print_map/worker.rb', line 12 def initialize(config = {}) @map_exporter = config[:map_exporter] || MapExporter.new @pdf_generator = config[:pdf_generator] || PdfGenerator.new @legend_images_collector = config[:legend_images_collector] || LegendImagesCollector.new end |
Instance Attribute Details
#current_job ⇒ Object (readonly)
Returns the value of attribute current_job.
9 10 11 |
# File 'lib/print_map/worker.rb', line 9 def current_job @current_job end |
#legend_images_collector ⇒ Object (readonly)
Returns the value of attribute legend_images_collector.
10 11 12 |
# File 'lib/print_map/worker.rb', line 10 def legend_images_collector @legend_images_collector end |
#map_exporter ⇒ Object (readonly)
Returns the value of attribute map_exporter.
10 11 12 |
# File 'lib/print_map/worker.rb', line 10 def map_exporter @map_exporter end |
#pdf_generator ⇒ Object (readonly)
Returns the value of attribute pdf_generator.
10 11 12 |
# File 'lib/print_map/worker.rb', line 10 def pdf_generator @pdf_generator end |
Instance Method Details
#collect_legend_images ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/print_map/worker.rb', line 62 def collect_legend_images images = [] current_job.services.each do |url| puts 'fetching legends at ' + url images << legend_images_collector.collect(:url => url) end images.flatten end |
#create_composite_map_image ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/print_map/worker.rb', line 31 def create_composite_map_image width, height = 540, 510 base_image = Magick::Image.new(width, height) base_image.background_color = 'transparent' base_image.format = 'PNG' current_job.services.each do |map_service| = { :service => map_service, :dpi => current_job.dpi, :bbox => current_job.bbox.join(','), :size => [width, height].join(',') } map_service_image = map_exporter.export() base_image.composite!(map_service_image, Magick::CenterGravity, Magick::OverCompositeOp) map_service_image.destroy! end base_image end |
#do_job(job) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/print_map/worker.rb', line 18 def do_job(job) @current_job = job puts 'create composite map image' map_image = create_composite_map_image puts 'collect legend images' legend_images = collect_legend_images puts 'generate pdf' pdf = generate_pdf(map_image, legend_images) puts 'cleanup' map_image.destroy! pdf end |
#generate_pdf(map_image, legend_images) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/print_map/worker.rb', line 52 def generate_pdf(map_image, legend_images) opts = { :title => current_job.title, :map_image => map_image, :page_layout => current_job.page_layout, :legend_images => legend_images } pdf_generator.generate(opts) end |