Class: JsonInference::NodeValuesCollection::ValueCounter
- Inherits:
-
Object
- Object
- JsonInference::NodeValuesCollection::ValueCounter
- Defined in:
- lib/json-inference.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #<<(value) ⇒ Object
-
#initialize(reported_class) ⇒ ValueCounter
constructor
A new instance of ValueCounter.
- #to_s(all_values_count) ⇒ Object
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
#size ⇒ Object (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 |