Class: HealthcarePhony::CsvFile
- Inherits:
-
Object
- Object
- HealthcarePhony::CsvFile
- Defined in:
- lib/healthcare_phony.rb
Instance Attribute Summary collapse
-
#csv_arguments ⇒ Object
readonly
Returns the value of attribute csv_arguments.
-
#number_of_rows ⇒ Object
readonly
Returns the value of attribute number_of_rows.
-
#template_file ⇒ Object
readonly
Returns the value of attribute template_file.
Instance Method Summary collapse
-
#initialize(init_args = {}) ⇒ CsvFile
constructor
(number_of_rows, template_file = nil).
- #to_file(file_name) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(init_args = {}) ⇒ CsvFile
(number_of_rows, template_file = nil)
61 62 63 64 65 |
# 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 |
Instance Attribute Details
#csv_arguments ⇒ Object (readonly)
Returns the value of attribute csv_arguments.
59 60 61 |
# File 'lib/healthcare_phony.rb', line 59 def csv_arguments @csv_arguments end |
#number_of_rows ⇒ Object (readonly)
Returns the value of attribute number_of_rows.
59 60 61 |
# File 'lib/healthcare_phony.rb', line 59 def number_of_rows @number_of_rows end |
#template_file ⇒ Object (readonly)
Returns the value of attribute template_file.
59 60 61 |
# File 'lib/healthcare_phony.rb', line 59 def template_file @template_file end |
Instance Method Details
#to_file(file_name) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# 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 ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# 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 |