Class: Eatr::Csv::Document
- Inherits:
-
Object
- Object
- Eatr::Csv::Document
- Extended by:
- Forwardable
- Includes:
- ParseValue
- Defined in:
- lib/eatr/csv/document.rb
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
-
#initialize(schema_path) ⇒ Document
constructor
A new instance of Document.
- #parse(csv_document_path) ⇒ Object
Methods included from ParseValue
Constructor Details
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
11 12 13 |
# File 'lib/eatr/csv/document.rb', line 11 def schema @schema end |
Instance Method Details
#parse(csv_document_path) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/eatr/csv/document.rb', line 20 def parse(csv_document_path) objects = [] CSV.foreach(csv_document_path, headers: true) do |row| obj = @schema.to_struct.new @schema.fields.each do |field| obj.public_send("#{field.name}=", value_at(row, field)) end objects << obj end objects end |