class EfoNelfo::Reader::CSV
Constants
- CSV_OPTIONS
- ENCODING
Attributes
csv[R]
data[R]
Public Class Methods
new(options)
click to toggle source
# File lib/efo_nelfo/reader/csv.rb, line 20 def initialize(options) if options[:filename] @data = File.read(options[:filename], encoding: ENCODING) else @data = options[:data].force_encoding ENCODING end @csv = ::CSV.new @data, CSV_OPTIONS end
Public Instance Methods
first()
click to toggle source
Returns the first row of the csv file
# File lib/efo_nelfo/reader/csv.rb, line 44 def first return @first if @first csv.rewind @first = csv.first end
head()
click to toggle source
# File lib/efo_nelfo/reader/csv.rb, line 50 def head return @head if @head klass = EfoNelfo::PostType.for first[0], first[2] raise EfoNelfo::UnsupportedPostType.new("Don't know how to handle v#{first[2]} of #{first[0]}") if klass.nil? @head = klass.new first end
parse()
click to toggle source
Parses the data and returns an EfoNelfo
object of some kind
# File lib/efo_nelfo/reader/csv.rb, line 31 def parse csv.each do |row| # Find the correct posttype module for given posttype and version klass = EfoNelfo::PostType.for row[0], head.version next if klass.nil? head.add klass.new(row) end head end