class DatasetExplorer::ValueEvaluator

Attributes

max_length[R]
min_length[R]

Public Class Methods

new(field_name) click to toggle source
# File lib/dataset_explorer/value_evaluator.rb, line 12
def initialize(field_name)
  @field_name = field_name
  @null = true
  @evaluators = {
    'date' => DateEvaluator.new,
    'time' => TimeEvaluator.new,
    'string' => StringEvaluator.new,
    'float' => FloatEvaluator.new,
    'integer' => IntegerEvaluator.new,
    'boolean' => BooleanEvaluator.new
  }
  @min_length = nil
  @max_length = nil
end

Public Instance Methods

describe() click to toggle source
# File lib/dataset_explorer/value_evaluator.rb, line 46
def describe
  parts = ["Possible types: [#{types.join(', ')}]"]
  if @null
    parts << 'NULL'
  end

  if min_length
    parts << "Min/max Length: #{min_length}/#{max_length}"
  end

  parts.join(', ')
end
evaluate(value) click to toggle source
# File lib/dataset_explorer/value_evaluator.rb, line 27
def evaluate(value)
  if value.nil?
    @null = true
    return
  end

  evaluate_length(value)

  @evaluators.each do |key, evaluator|
    unless evaluator.accept?(value)
      @evaluators.delete(key)
    end
  end
end
evaluate_length(value) click to toggle source
# File lib/dataset_explorer/value_evaluator.rb, line 59
def evaluate_length(value)
  unless value.respond_to?(:length)
    return
  end

  length = value.length
  @min_length ||= length
  @max_length ||= length

  if @min_length > length
    @min_length = length
  end

  if @max_length < length
    @max_length = length
  end
end
types() click to toggle source
# File lib/dataset_explorer/value_evaluator.rb, line 42
def types
  @evaluators.keys
end