Class: Reading::Line

Inherits:
Object show all
Defined in:
lib/reading/line.rb

Overview

A bridge between rows as strings and as parsable Rows, used whenever the context of the line in the CSV is needed, e.g. converting a line to a Row, or adding a CSV line to a Row parsing error.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, csv) ⇒ Line

Returns a new instance of Line.



12
13
14
15
# File 'lib/reading/line.rb', line 12

def initialize(string, csv)
  @string = string.dup.force_encoding(Encoding::UTF_8).strip
  @csv = csv
end

Instance Attribute Details

#csvObject (readonly)

Returns the value of attribute csv.



10
11
12
# File 'lib/reading/line.rb', line 10

def csv
  @csv
end

#stringObject (readonly)

Returns the value of attribute string.



10
11
12
# File 'lib/reading/line.rb', line 10

def string
  @string
end

Instance Method Details

#to_rowObject



17
18
19
20
21
# File 'lib/reading/line.rb', line 17

def to_row
  return CompactPlannedRow.new(self) if CompactPlannedRow.match?(self)
  return BlankRow.new(self) if BlankRow.match?(self)
  RegularRow.new(self)
end