Class: Sycsvpro::Analyzer
- Inherits:
-
Object
- Object
- Sycsvpro::Analyzer
- Defined in:
- lib/sycsvpro/analyzer.rb
Overview
Analyzes the file structure
| Name | C1 | C2 | | A | a | b |
3 columns: [“Name”, “C1”, “C2”] 2 rows
Row sample data: A;b;c
Column index: Column name | Column sample value 0: Name | A 1: C1 | a 2: C2 | b
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
28 29 30 |
# File 'lib/sycsvpro/analyzer.rb', line 28 def initialize(file) @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
File that is analyzed
25 26 27 |
# File 'lib/sycsvpro/analyzer.rb', line 25 def file @file end |
Instance Method Details
#result ⇒ Object
Analyzes the file and returns the result
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sycsvpro/analyzer.rb', line 33 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 |