Class: Mode::Commands::AnalyzeField

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/mode/commands/analyze_field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#config_dir, #config_exists?, #config_path, #configure_api_requests!, #connect_config_exists?, #require_config!, #require_connect_config!, #require_credentials!, #timer_block

Constructor Details

#initialize(path, field_pos, options = {}) ⇒ AnalyzeField

Returns a new instance of AnalyzeField.



12
13
14
15
16
# File 'lib/mode/commands/analyze_field.rb', line 12

def initialize(path, field_pos, options = {})
  @path = path
  @field_pos = field_pos.to_i
  @options = options
end

Instance Attribute Details

#field_posObject

Returns the value of attribute field_pos.



9
10
11
# File 'lib/mode/commands/analyze_field.rb', line 9

def field_pos
  @field_pos
end

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/mode/commands/analyze_field.rb', line 10

def options
  @options
end

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/mode/commands/analyze_field.rb', line 8

def path
  @path
end

Instance Method Details

#executeObject



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

def execute
  if path.nil? || !File.exist?(path)
    puts "Error: Couldn't find file at #{path}"
    return
  end

  csv = DataKit::CSV::Parser.new(path)

  field_name = csv.headers[field_pos]

  puts "Analyzing #{field_name} at #{path || 'input'}"

  analysis, total_time = timer_block do
    DataKit::CSV::FieldAnalyzer.analyze(csv, field_pos, {
      :match_type => match_type, :sampling_rate => 1
    })
  end

  puts "Analyzed #{analysis.row_count} rows in #{'%.2f' % total_time} seconds\n"

  display(analysis)
end