class CsvBlueprints::RepeatedValue
Attributes
value[R]
Public Class Methods
new(callable, max_repetitions)
click to toggle source
# File lib/csv_blueprints/blueprint.rb, line 13 def initialize(callable, max_repetitions) @callable = callable @max_repetitions = max_repetitions @repetitions = 0 @value = nil end
Public Instance Methods
call(index)
click to toggle source
# File lib/csv_blueprints/blueprint.rb, line 20 def call(index) calculate_value(index) increment_repetitions value end
Private Instance Methods
calculate_value(index)
click to toggle source
# File lib/csv_blueprints/blueprint.rb, line 30 def calculate_value(index) if @repetitions < @max_repetitions @value ||= @callable.call(index) else @repetitions = 0 @value = @callable.call(index) end end
increment_repetitions()
click to toggle source
# File lib/csv_blueprints/blueprint.rb, line 39 def increment_repetitions @repetitions += 1 end