class DwCAContentAnalyzer::FileContents

Attributes

columns[R]

Public Class Methods

new(file, detectors = %i[type length]) click to toggle source
# File lib/dwca_content_analyzer/file_contents.rb, line 14
def initialize(file, detectors = %i[type length])
  @file = file
  @detectors = detectors
  @columns = analyze
end

Private Instance Methods

analyze() click to toggle source
# File lib/dwca_content_analyzer/file_contents.rb, line 22
def analyze
  table = load_table @file
  table.by_col!.map do |col|
    header = col[0]
    contents = col[1]
    Column.new(header.to_i, contents, *@detectors)
  end
end
headers(file) click to toggle source

reads the first line of the CSV file returns the columns indices as an array

# File lib/dwca_content_analyzer/file_contents.rb, line 33
def headers(file)
  Array.new(CSV.open(file, &:readline).size) { |i| i.to_s }
end
load_table(file) click to toggle source
# File lib/dwca_content_analyzer/file_contents.rb, line 37
def load_table(file)
  CSV.read(file,
           headers: headers(file),
           converters: %i[blank_to_nil safe_numeric date])
end