Class: JsonInference::NodeValuesCollection::ValueCounter

Inherits:
Object
  • Object
show all
Defined in:
lib/json-inference.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reported_class) ⇒ ValueCounter

Returns a new instance of ValueCounter.



58
59
60
61
62
# File 'lib/json-inference.rb', line 58

def initialize(reported_class)
  @reported_class = reported_class
  @size = 0
  @empties = 0
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



56
57
58
# File 'lib/json-inference.rb', line 56

def size
  @size
end

Instance Method Details

#<<(value) ⇒ Object



64
65
66
67
68
69
# File 'lib/json-inference.rb', line 64

def <<(value)
  @size += 1
  if [Array, String].include?(@reported_class)
    @empties += 1 if value.empty?
  end
end

#to_s(all_values_count) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/json-inference.rb', line 71

def to_s(all_values_count)
  str = "#{@reported_class}: #{JsonInference.percent_string(size, all_values_count)}"
  if [Array, String].include?(@reported_class)
    str << ", #{JsonInference.percent_string(@empties, size)} empty"
  end
  str
end