Class: AbcSizeVisualizer::IntegerOnLocation
- Inherits:
-
Object
- Object
- AbcSizeVisualizer::IntegerOnLocation
- Defined in:
- lib/abc_size_visualizer/integer_on_location.rb
Instance Attribute Summary collapse
-
#value_by_line_num ⇒ Object
readonly
Returns the value of attribute value_by_line_num.
Instance Method Summary collapse
- #add(node, value) ⇒ Object
-
#initialize ⇒ IntegerOnLocation
constructor
A new instance of IntegerOnLocation.
- #line_nums ⇒ Object
- #to_i ⇒ Object
- #value_at(line_num:) ⇒ Object
Constructor Details
#initialize ⇒ IntegerOnLocation
Returns a new instance of IntegerOnLocation.
5 6 7 |
# File 'lib/abc_size_visualizer/integer_on_location.rb', line 5 def initialize @value_by_line_num = {} end |
Instance Attribute Details
#value_by_line_num ⇒ Object (readonly)
Returns the value of attribute value_by_line_num.
3 4 5 |
# File 'lib/abc_size_visualizer/integer_on_location.rb', line 3 def value_by_line_num @value_by_line_num end |
Instance Method Details
#add(node, value) ⇒ Object
9 10 11 12 13 |
# File 'lib/abc_size_visualizer/integer_on_location.rb', line 9 def add(node, value) line_num = node.loc.expression.line @value_by_line_num[line_num] ||= 0 @value_by_line_num[line_num] += value end |
#line_nums ⇒ Object
23 24 25 |
# File 'lib/abc_size_visualizer/integer_on_location.rb', line 23 def line_nums @value_by_line_num.keys end |
#to_i ⇒ Object
19 20 21 |
# File 'lib/abc_size_visualizer/integer_on_location.rb', line 19 def to_i @value_by_line_num.values.sum || 0 end |
#value_at(line_num:) ⇒ Object
15 16 17 |
# File 'lib/abc_size_visualizer/integer_on_location.rb', line 15 def value_at(line_num:) @value_by_line_num[line_num] end |