Class: AbcSizeVisualizer::IntegerOnLocation

Inherits:
Object
  • Object
show all
Defined in:
lib/abc_size_visualizer/integer_on_location.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIntegerOnLocation

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_numObject (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
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_numsObject



23
24
25
# File 'lib/abc_size_visualizer/integer_on_location.rb', line 23

def line_nums
  @value_by_line_num.keys
end

#to_iObject



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