Class: CsvImportAnalyzer::CsvDatatypeAnalysis
- Inherits:
-
Object
- Object
- CsvImportAnalyzer::CsvDatatypeAnalysis
- Includes:
- DatatypeValidator, Helper
- Defined in:
- lib/csv-import-analyzer/csv_datatype_analysis.rb
Instance Attribute Summary collapse
-
#csv_column_datatypes ⇒ Object
Returns the value of attribute csv_column_datatypes.
-
#nullable ⇒ Object
Returns the value of attribute nullable.
Instance Method Summary collapse
-
#datatype_analysis ⇒ Object
Process a chunk of csv file for all possible datatypes towards each column in the row This datatype analysis is used for analyzing, Min - Max values of each column Distinct values of each column Enumeration eligibility.
- #filename ⇒ Object
-
#initialize(options) ⇒ CsvDatatypeAnalysis
constructor
A new instance of CsvDatatypeAnalysis.
- #options ⇒ Object
Methods included from DatatypeValidator
Methods included from Helper
Constructor Details
#initialize(options) ⇒ CsvDatatypeAnalysis
Returns a new instance of CsvDatatypeAnalysis.
15 16 17 18 19 |
# File 'lib/csv-import-analyzer/csv_datatype_analysis.rb', line 15 def initialize() = @csv_column_datatypes = {} @nullable = [] end |
Instance Attribute Details
#csv_column_datatypes ⇒ Object
Returns the value of attribute csv_column_datatypes.
13 14 15 |
# File 'lib/csv-import-analyzer/csv_datatype_analysis.rb', line 13 def csv_column_datatypes @csv_column_datatypes end |
#nullable ⇒ Object
Returns the value of attribute nullable.
13 14 15 |
# File 'lib/csv-import-analyzer/csv_datatype_analysis.rb', line 13 def nullable @nullable end |
Instance Method Details
#datatype_analysis ⇒ Object
Process a chunk of csv file for all possible datatypes towards each column in the row This datatype analysis is used for analyzing,
Min - Max values of each column
Distinct values of each column
Enumeration eligibility
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/csv-import-analyzer/csv_datatype_analysis.rb', line 35 def datatype_analysis SmarterCSV.process(filename, {:col_sep => delimiter, :chunk_size => chunk_size, :remove_empty_values => false, :remove_zero_values => false}) do |chunk| chunk.each do |row| row.each do |key, value| unless null_like?(value) datatype = determine_dataype(value) add_to_datatype(key, datatype.to_sym) else nullable.push(key) unless nullable.include?(key) end end end break end [:csv_datatype_analysis] = csv_column_datatypes.clone # To retain the current state of csv_column_datatypes since it's altered further finalize_datatypes_for_csv [:csv_column_datatypes] = csv_column_datatypes [:nullable] = nullable take_further_actions end |
#filename ⇒ Object
25 26 27 |
# File 'lib/csv-import-analyzer/csv_datatype_analysis.rb', line 25 def filename [:filename] end |
#options ⇒ Object
21 22 23 |
# File 'lib/csv-import-analyzer/csv_datatype_analysis.rb', line 21 def end |