Class: TaxGenerator::FileCreator
- Inherits:
-
Object
- Object
- TaxGenerator::FileCreator
- Includes:
- Celluloid, Celluloid::Logger, ApplicationHelper
- Defined in:
- lib/tax_generator/classes/file_creator.rb
Overview
class used to create the files
Instance Attribute Summary collapse
-
#destination ⇒ Nokogiri::Element
The destination node from the xml document.
-
#job ⇒ Hash
The job that this actor received.
-
#job_id ⇒ String
The id of the node from the taxonomy tree.
-
#output_folder ⇒ String
The output folder where the new files will be created.
-
#processor ⇒ TaxGenerator::Processor
The manager that manages the current actor.
-
#taxonomy ⇒ TaxGenerator::TaxonomyTree
The taxonomy tree holding all the nodes from the taxonomy xml document.
Instance Method Summary collapse
-
#fetch_atlas_details ⇒ void
fetches the details needed to be passed to the erb template.
-
#mark_job_completed ⇒ void
marks the job as completed after file is generated.
-
#process_job(job) ⇒ void
processes the job information by retrieving keys from the hash.
-
#start_work ⇒ void
renders the template and creates new file with the template html.
-
#template_name ⇒ void
returns the template file path used for generating the files.
-
#work(job, manager) ⇒ void
processes the job received and registers itself inside the manager.
Methods included from ApplicationHelper
create_directories, elements_with_content, erb_template, execute_with_rescue, format_error, log_error, log_message, nokogiri_xml, rescue_interrupt, root, set_celluloid_exception_handling
Instance Attribute Details
#destination ⇒ Nokogiri::Element
Returns the destination node from the xml document.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/tax_generator/classes/file_creator.rb', line 17 class FileCreator include Celluloid include Celluloid::Logger include TaxGenerator::ApplicationHelper attr_reader :processor, :job, :job_id, :destination, :taxonomy, :output_folder # returns the template file path used for generating the files # # @return [void] # # @api public def template_name File.join(root, 'templates', 'template.html.erb') end # processes the job received and registers itself inside the manager # @see TaxGenerator::Processor#register_worker_for_job # @see #process_job # # @param [Hash] job the job that is passed to the current actor # @param [TaxGenerator::Processor] manager the manager that manages the actor # # @return [void] # # @api public def work(job, manager) job = job.stringify_keys @job = job @processor = manager process_job(job) @processor.register_worker_for_job(job, Actor.current) end # processes the job information by retrieving keys from the hash # # @param [Hash] job the job that is passed to the current actor # # @return [void] # # @api public def process_job(job) job = job.stringify_keys @destination = job['destination'] @job_id = job['atlas_id'] @taxonomy = job['taxonomy'] @output_folder = job['output_folder'] end # renders the template and creates new file with the template html # # @return [void] # # @api public def start_work "Generating html for destination #{@job_id}" output = Tilt.new(template_name).render(Actor.current, fetch_atlas_details) File.open(File.join(@output_folder, "#{@job_id}.html"), 'w') { |file| file << output } mark_job_completed end # marks the job as completed after file is generated # # @return [void] # # @api public def mark_job_completed @processor.jobs[@job_id]['status'] = 'finished' end # fetches the details needed to be passed to the erb template # @see TaxGenerator::Destination#new # # @return [void] # # @api public def fetch_atlas_details atlas_node = @taxonomy[@job_id] content = @destination.present? ? TaxGenerator::Destination.new(@destination).to_hash : {} content.merge(details: atlas_node) end end |
#job ⇒ Hash
Returns the job that this actor received.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/tax_generator/classes/file_creator.rb', line 17 class FileCreator include Celluloid include Celluloid::Logger include TaxGenerator::ApplicationHelper attr_reader :processor, :job, :job_id, :destination, :taxonomy, :output_folder # returns the template file path used for generating the files # # @return [void] # # @api public def template_name File.join(root, 'templates', 'template.html.erb') end # processes the job received and registers itself inside the manager # @see TaxGenerator::Processor#register_worker_for_job # @see #process_job # # @param [Hash] job the job that is passed to the current actor # @param [TaxGenerator::Processor] manager the manager that manages the actor # # @return [void] # # @api public def work(job, manager) job = job.stringify_keys @job = job @processor = manager process_job(job) @processor.register_worker_for_job(job, Actor.current) end # processes the job information by retrieving keys from the hash # # @param [Hash] job the job that is passed to the current actor # # @return [void] # # @api public def process_job(job) job = job.stringify_keys @destination = job['destination'] @job_id = job['atlas_id'] @taxonomy = job['taxonomy'] @output_folder = job['output_folder'] end # renders the template and creates new file with the template html # # @return [void] # # @api public def start_work "Generating html for destination #{@job_id}" output = Tilt.new(template_name).render(Actor.current, fetch_atlas_details) File.open(File.join(@output_folder, "#{@job_id}.html"), 'w') { |file| file << output } mark_job_completed end # marks the job as completed after file is generated # # @return [void] # # @api public def mark_job_completed @processor.jobs[@job_id]['status'] = 'finished' end # fetches the details needed to be passed to the erb template # @see TaxGenerator::Destination#new # # @return [void] # # @api public def fetch_atlas_details atlas_node = @taxonomy[@job_id] content = @destination.present? ? TaxGenerator::Destination.new(@destination).to_hash : {} content.merge(details: atlas_node) end end |
#job_id ⇒ String
Returns the id of the node from the taxonomy tree.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/tax_generator/classes/file_creator.rb', line 17 class FileCreator include Celluloid include Celluloid::Logger include TaxGenerator::ApplicationHelper attr_reader :processor, :job, :job_id, :destination, :taxonomy, :output_folder # returns the template file path used for generating the files # # @return [void] # # @api public def template_name File.join(root, 'templates', 'template.html.erb') end # processes the job received and registers itself inside the manager # @see TaxGenerator::Processor#register_worker_for_job # @see #process_job # # @param [Hash] job the job that is passed to the current actor # @param [TaxGenerator::Processor] manager the manager that manages the actor # # @return [void] # # @api public def work(job, manager) job = job.stringify_keys @job = job @processor = manager process_job(job) @processor.register_worker_for_job(job, Actor.current) end # processes the job information by retrieving keys from the hash # # @param [Hash] job the job that is passed to the current actor # # @return [void] # # @api public def process_job(job) job = job.stringify_keys @destination = job['destination'] @job_id = job['atlas_id'] @taxonomy = job['taxonomy'] @output_folder = job['output_folder'] end # renders the template and creates new file with the template html # # @return [void] # # @api public def start_work "Generating html for destination #{@job_id}" output = Tilt.new(template_name).render(Actor.current, fetch_atlas_details) File.open(File.join(@output_folder, "#{@job_id}.html"), 'w') { |file| file << output } mark_job_completed end # marks the job as completed after file is generated # # @return [void] # # @api public def mark_job_completed @processor.jobs[@job_id]['status'] = 'finished' end # fetches the details needed to be passed to the erb template # @see TaxGenerator::Destination#new # # @return [void] # # @api public def fetch_atlas_details atlas_node = @taxonomy[@job_id] content = @destination.present? ? TaxGenerator::Destination.new(@destination).to_hash : {} content.merge(details: atlas_node) end end |
#output_folder ⇒ String
Returns the output folder where the new files will be created.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/tax_generator/classes/file_creator.rb', line 17 class FileCreator include Celluloid include Celluloid::Logger include TaxGenerator::ApplicationHelper attr_reader :processor, :job, :job_id, :destination, :taxonomy, :output_folder # returns the template file path used for generating the files # # @return [void] # # @api public def template_name File.join(root, 'templates', 'template.html.erb') end # processes the job received and registers itself inside the manager # @see TaxGenerator::Processor#register_worker_for_job # @see #process_job # # @param [Hash] job the job that is passed to the current actor # @param [TaxGenerator::Processor] manager the manager that manages the actor # # @return [void] # # @api public def work(job, manager) job = job.stringify_keys @job = job @processor = manager process_job(job) @processor.register_worker_for_job(job, Actor.current) end # processes the job information by retrieving keys from the hash # # @param [Hash] job the job that is passed to the current actor # # @return [void] # # @api public def process_job(job) job = job.stringify_keys @destination = job['destination'] @job_id = job['atlas_id'] @taxonomy = job['taxonomy'] @output_folder = job['output_folder'] end # renders the template and creates new file with the template html # # @return [void] # # @api public def start_work "Generating html for destination #{@job_id}" output = Tilt.new(template_name).render(Actor.current, fetch_atlas_details) File.open(File.join(@output_folder, "#{@job_id}.html"), 'w') { |file| file << output } mark_job_completed end # marks the job as completed after file is generated # # @return [void] # # @api public def mark_job_completed @processor.jobs[@job_id]['status'] = 'finished' end # fetches the details needed to be passed to the erb template # @see TaxGenerator::Destination#new # # @return [void] # # @api public def fetch_atlas_details atlas_node = @taxonomy[@job_id] content = @destination.present? ? TaxGenerator::Destination.new(@destination).to_hash : {} content.merge(details: atlas_node) end end |
#processor ⇒ TaxGenerator::Processor
Returns the manager that manages the current actor.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/tax_generator/classes/file_creator.rb', line 17 class FileCreator include Celluloid include Celluloid::Logger include TaxGenerator::ApplicationHelper attr_reader :processor, :job, :job_id, :destination, :taxonomy, :output_folder # returns the template file path used for generating the files # # @return [void] # # @api public def template_name File.join(root, 'templates', 'template.html.erb') end # processes the job received and registers itself inside the manager # @see TaxGenerator::Processor#register_worker_for_job # @see #process_job # # @param [Hash] job the job that is passed to the current actor # @param [TaxGenerator::Processor] manager the manager that manages the actor # # @return [void] # # @api public def work(job, manager) job = job.stringify_keys @job = job @processor = manager process_job(job) @processor.register_worker_for_job(job, Actor.current) end # processes the job information by retrieving keys from the hash # # @param [Hash] job the job that is passed to the current actor # # @return [void] # # @api public def process_job(job) job = job.stringify_keys @destination = job['destination'] @job_id = job['atlas_id'] @taxonomy = job['taxonomy'] @output_folder = job['output_folder'] end # renders the template and creates new file with the template html # # @return [void] # # @api public def start_work "Generating html for destination #{@job_id}" output = Tilt.new(template_name).render(Actor.current, fetch_atlas_details) File.open(File.join(@output_folder, "#{@job_id}.html"), 'w') { |file| file << output } mark_job_completed end # marks the job as completed after file is generated # # @return [void] # # @api public def mark_job_completed @processor.jobs[@job_id]['status'] = 'finished' end # fetches the details needed to be passed to the erb template # @see TaxGenerator::Destination#new # # @return [void] # # @api public def fetch_atlas_details atlas_node = @taxonomy[@job_id] content = @destination.present? ? TaxGenerator::Destination.new(@destination).to_hash : {} content.merge(details: atlas_node) end end |
#taxonomy ⇒ TaxGenerator::TaxonomyTree
Returns the taxonomy tree holding all the nodes from the taxonomy xml document.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/tax_generator/classes/file_creator.rb', line 17 class FileCreator include Celluloid include Celluloid::Logger include TaxGenerator::ApplicationHelper attr_reader :processor, :job, :job_id, :destination, :taxonomy, :output_folder # returns the template file path used for generating the files # # @return [void] # # @api public def template_name File.join(root, 'templates', 'template.html.erb') end # processes the job received and registers itself inside the manager # @see TaxGenerator::Processor#register_worker_for_job # @see #process_job # # @param [Hash] job the job that is passed to the current actor # @param [TaxGenerator::Processor] manager the manager that manages the actor # # @return [void] # # @api public def work(job, manager) job = job.stringify_keys @job = job @processor = manager process_job(job) @processor.register_worker_for_job(job, Actor.current) end # processes the job information by retrieving keys from the hash # # @param [Hash] job the job that is passed to the current actor # # @return [void] # # @api public def process_job(job) job = job.stringify_keys @destination = job['destination'] @job_id = job['atlas_id'] @taxonomy = job['taxonomy'] @output_folder = job['output_folder'] end # renders the template and creates new file with the template html # # @return [void] # # @api public def start_work "Generating html for destination #{@job_id}" output = Tilt.new(template_name).render(Actor.current, fetch_atlas_details) File.open(File.join(@output_folder, "#{@job_id}.html"), 'w') { |file| file << output } mark_job_completed end # marks the job as completed after file is generated # # @return [void] # # @api public def mark_job_completed @processor.jobs[@job_id]['status'] = 'finished' end # fetches the details needed to be passed to the erb template # @see TaxGenerator::Destination#new # # @return [void] # # @api public def fetch_atlas_details atlas_node = @taxonomy[@job_id] content = @destination.present? ? TaxGenerator::Destination.new(@destination).to_hash : {} content.merge(details: atlas_node) end end |
Instance Method Details
#fetch_atlas_details ⇒ void
This method returns an undefined value.
fetches the details needed to be passed to the erb template
93 94 95 96 97 |
# File 'lib/tax_generator/classes/file_creator.rb', line 93 def fetch_atlas_details atlas_node = @taxonomy[@job_id] content = @destination.present? ? TaxGenerator::Destination.new(@destination).to_hash : {} content.merge(details: atlas_node) end |
#mark_job_completed ⇒ void
This method returns an undefined value.
marks the job as completed after file is generated
83 84 85 |
# File 'lib/tax_generator/classes/file_creator.rb', line 83 def mark_job_completed @processor.jobs[@job_id]['status'] = 'finished' end |
#process_job(job) ⇒ void
This method returns an undefined value.
processes the job information by retrieving keys from the hash
58 59 60 61 62 63 64 |
# File 'lib/tax_generator/classes/file_creator.rb', line 58 def process_job(job) job = job.stringify_keys @destination = job['destination'] @job_id = job['atlas_id'] @taxonomy = job['taxonomy'] @output_folder = job['output_folder'] end |
#start_work ⇒ void
This method returns an undefined value.
renders the template and creates new file with the template html
71 72 73 74 75 76 |
# File 'lib/tax_generator/classes/file_creator.rb', line 71 def start_work "Generating html for destination #{@job_id}" output = Tilt.new(template_name).render(Actor.current, fetch_atlas_details) File.open(File.join(@output_folder, "#{@job_id}.html"), 'w') { |file| file << output } mark_job_completed end |
#template_name ⇒ void
This method returns an undefined value.
returns the template file path used for generating the files
29 30 31 |
# File 'lib/tax_generator/classes/file_creator.rb', line 29 def template_name File.join(root, 'templates', 'template.html.erb') end |
#work(job, manager) ⇒ void
This method returns an undefined value.
processes the job received and registers itself inside the manager
43 44 45 46 47 48 49 |
# File 'lib/tax_generator/classes/file_creator.rb', line 43 def work(job, manager) job = job.stringify_keys @job = job @processor = manager process_job(job) @processor.register_worker_for_job(job, Actor.current) end |