Class: PointAndFigure::PointGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/point_and_figure/point_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_point, current_value, prev_value, current_line, output_data) ⇒ PointGenerator

Returns a new instance of PointGenerator.



3
4
5
6
7
8
9
10
11
# File 'lib/point_and_figure/point_generator.rb', line 3

def initialize(base_point, current_value, prev_value, current_line, output_data)
  @base_point = base_point
  @current_value = current_value
  @prev_value = prev_value
  @current_line = current_line
  @output_data = output_data
  @round_unit = PointAndFigure.calc_round_unit base_point
  @flame = ((current_value - prev_value) / base_point).round.abs
end

Instance Method Details

#generate(trend:, trend_changed: false) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/point_and_figure/point_generator.rb', line 13

def generate(trend:, trend_changed: false)
  operator = trend == :up ? :+ : :-
  @output_data.tap do |output_data|
    (0...@flame).each do |i|
      next if i == 0 && trend_changed
      output_data[:data_set] << [@current_line,
                                 (@prev_value.send(operator, @base_point * i)).round(@round_unit),
                                 (@prev_value.send(operator, @base_point * (i + 1))).round(@round_unit)]
    end
  end
end