Module: TabularData

Defined in:
lib/tabular_data.rb,
lib/tabular_data/version.rb

Defined Under Namespace

Modules: Strategies Classes: Reader

Constant Summary collapse

VERSION =
"0.0.21"

Class Method Summary collapse

Class Method Details

.parse_csv(path, attributes, factory, column_delimiter = ";") ⇒ Object



16
17
18
# File 'lib/tabular_data.rb', line 16

def self.parse_csv(path, attributes, factory, column_delimiter = ";")
    parse_lines File.open(path, "r").readlines, attributes, factory, column_delimiter
end

.parse_lines(lines, attributes, factory, column_delimiter = ";") ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/tabular_data.rb', line 3

def self.parse_lines(lines, attributes, factory, column_delimiter = ";")
    lines = lines.split("\n") if lines.is_a? String
    
    reader = TabularData::Reader.new(attributes)
    reader.strategy = TabularData::Strategies::CSVStrategy.new(column_delimiter)
    
    entries = []
    lines.each do |line|
        entries << reader.read(factory.call, line.strip)
    end
    entries
end