Class: Mode::Sdk::CsvFile

Inherits:
Object
  • Object
show all
Defined in:
lib/mode/sdk/csv_file.rb

Overview

Represents a local CSV file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_path) ⇒ Mode::Sdk::CsvFile

Construct a new CsvFile instance


20
21
22
# File 'lib/mode/sdk/csv_file.rb', line 20

def initialize(original_path)
  @original_path = original_path
end

Instance Attribute Details

#original_pathString (readonly)

the path of the file


11
12
13
# File 'lib/mode/sdk/csv_file.rb', line 11

def original_path
  @original_path
end

Instance Method Details

#contentString

All lines of the file except the header with standardized LF line breaks


77
78
79
# File 'lib/mode/sdk/csv_file.rb', line 77

def content
  @content ||= lines[1..-1].join("\n")
end

#headerArray<String>

An array of parsed CSV header column names


68
69
70
# File 'lib/mode/sdk/csv_file.rb', line 68

def header
  @header ||= CSV.parse_line(lines[0])
end

#line_countInteger

The total number of lines in the file


60
61
62
# File 'lib/mode/sdk/csv_file.rb', line 60

def line_count
  @line_count ||= lines.size
end

#linesArray<String>

An array of all lines in the file


52
53
54
# File 'lib/mode/sdk/csv_file.rb', line 52

def lines
  @lines ||= File.open(path, 'r', &:read).split(/[\r\n]+/)
end

#nameString

The base name of the file with CSV extension removed, if present


36
37
38
# File 'lib/mode/sdk/csv_file.rb', line 36

def name
  File.basename(path, '.csv')
end

#pathString

The expanded path of the file


28
29
30
# File 'lib/mode/sdk/csv_file.rb', line 28

def path
  @path ||= File.expand_path(original_path)
end

#sizeInteger

The size of the file


44
45
46
# File 'lib/mode/sdk/csv_file.rb', line 44

def size
  @size ||= File.size(path)
end