Class: Sycsvpro::Analyzer
- Inherits:
-
Object
- Object
- Sycsvpro::Analyzer
- Defined in:
- lib/sycsvpro/analyzer.rb
Overview
Analyzes the file structure
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
File that is analyzed.
Instance Method Summary collapse
-
#initialize(file) ⇒ Analyzer
constructor
Creates a new analyzer.
-
#result ⇒ Object
Analyzes the file and returns the result.
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
#file ⇒ Object (readonly)
File that is analyzed
11 12 13 |
# File 'lib/sycsvpro/analyzer.rb', line 11 def file @file end |
Instance Method Details
#result ⇒ Object
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 |