class HealthcarePhony::CsvFile
Attributes
csv_arguments[R]
number_of_rows[R]
template_file[R]
Public Class Methods
new(init_args = {})
click to toggle source
# File lib/healthcare_phony.rb, line 61 def initialize(init_args = {}) #(number_of_rows, template_file = nil) @csv_arguments = init_args @number_of_rows = @csv_arguments[:number_of_rows] #@csv_arguments[:number_of_rows].nil? ? 1 : @csv_arguments[:number_of_rows] set_template end
Public Instance Methods
to_file(file_name)
click to toggle source
# File lib/healthcare_phony.rb, line 78 def to_file(file_name) template = ERB.new(File.read(@template_file), trim_mode: '<>') counter = 0 output_file = File.open(file_name, 'w') while counter < @number_of_rows output_file.write("#{template.result_with_hash({ patient: Patient.new(@csv_arguments), write_header: counter.zero? })}\n") counter += 1 end output_file.close return output_file end
to_s()
click to toggle source
# File lib/healthcare_phony.rb, line 67 def to_s template = ERB.new(File.read(@template_file), trim_mode: '<>') counter = 0 output_string = '' while counter < @number_of_rows output_string += "#{template.result_with_hash({ patient: Patient.new(@csv_arguments), write_header: counter.zero? })}\n" counter += 1 end output_string end
Private Instance Methods
set_template()
click to toggle source
# File lib/healthcare_phony.rb, line 94 def set_template unless @csv_arguments[:template].nil? @template_file = @csv_arguments[:template] return end @template_file = if @csv_arguments[:template_file].nil? File.join(File.dirname(__FILE__), 'healthcare_phony', 'templates', 'csv_example.erb') #File.read(File.join(File.dirname(__FILE__), 'healthcare_phony', 'templates', 'csv_example.erb')) else @csv_arguments[:template_file] end end