Class: Sycsvpro::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/sycsvpro/analyzer.rb

Overview

Analyzes the file structure

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Analyzer

Creates a new analyzer



14
15
16
# File 'lib/sycsvpro/analyzer.rb', line 14

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

File that is analyzed



11
12
13
# File 'lib/sycsvpro/analyzer.rb', line 11

def file
  @file
end

Instance Method Details

#resultObject

Analyzes the file and returns the result



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sycsvpro/analyzer.rb', line 19

def result
  rows = File.readlines(file)

  result = Result.new
  unless rows.empty?
    row_number = 0
    row_number += 1 while rows[row_number].chomp.empty?

    result.cols       = rows[row_number].chomp.split(';')
    result.col_count  = result.cols.size

    row_number += 1
    row_number += 1 while rows[row_number].chomp.empty?

    result.row_count  = rows.size - 1
    result.sample_row = rows[row_number].chomp
  end

  result
end