class TaxGenerator::FileCreator
class used to create the files
@!attribute processor
@return [TaxGenerator::Processor] the manager that manages the current actor
@!attribute job
@return [Hash] the job that this actor received
@!attribute job_id
@return [String] the id of the node from the taxonomy tree
@!attribute destination
@return [Nokogiri::Element] the destination node from the xml document
@!attribute taxonomy
@return [TaxGenerator::TaxonomyTree] the taxonomy tree holding all the nodes from the taxonomy xml document
@!attribute output_folder
@return [String] the output folder where the new files will be created
Attributes
destination[R]
job[R]
job_id[R]
output_folder[R]
processor[R]
taxonomy[R]
Public Class Methods
new(*args)
click to toggle source
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
# File lib/tax_generator/classes/file_creator.rb, line 44 def initialize(*args) job = args[0] @processor = args[1] job = job.stringify_keys @job = job process_job(job) processor.register_worker_for_job(job, self) end
Public Instance Methods
atlas_node()
click to toggle source
finds all the nodes in the tree with the given name
@return [Array<Tree::TreeNode>]
@api public
# File lib/tax_generator/classes/file_creator.rb, line 73 def atlas_node @taxonomy.find_by_name(@job_id).first end
fetch_atlas_details()
click to toggle source
fetches the details needed to be passed to the erb template @see TaxGenerator::Destination#new
@return [void]
@api public
# File lib/tax_generator/classes/file_creator.rb, line 104 def fetch_atlas_details content = @destination.present? ? TaxGenerator::Destination.new(@destination).to_hash : {} content.merge(details: atlas_node) end
mark_job_completed()
click to toggle source
marks the job as completed after file is generated
@return [void]
@api public
# File lib/tax_generator/classes/file_creator.rb, line 94 def mark_job_completed @processor.jobs[@job_id]['status'] = 'finished' end
process_job(job)
click to toggle source
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
# File lib/tax_generator/classes/file_creator.rb, line 60 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()
click to toggle source
renders the template and creates new file with the template html
@return [void]
@api public
# File lib/tax_generator/classes/file_creator.rb, line 82 def start_work log_message "Generating html for destination #{@job_id}" output = Tilt.new(template_name).render(nil, fetch_atlas_details) File.open(File.join(@output_folder, "#{@job_id}.html"), 'w') { |file| file << output } mark_job_completed end
template_name()
click to toggle source
returns the template file path used for generating the files
@return [void]
@api public
# File lib/tax_generator/classes/file_creator.rb, line 30 def template_name File.join(root, 'templates', 'template.html.erb') end