Class: SmartRounding

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

Instance Method Summary collapse

Constructor Details

#initialize(array) ⇒ SmartRounding

Returns a new instance of SmartRounding.



2
3
4
# File 'lib/smart_rounding.rb', line 2

def initialize array
  @array = array
end

Instance Method Details

#rounded_arrayObject



10
11
12
# File 'lib/smart_rounding.rb', line 10

def rounded_array
  array.each_with_index.map{ |number, index| indexes_of_ceil_numbers.include?(index) ? number.ceil : number.floor }
end

#rounded_sumObject



6
7
8
# File 'lib/smart_rounding.rb', line 6

def rounded_sum
  array.inject(:+).round()
end

#rounds_equal?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/smart_rounding.rb', line 14

def rounds_equal?
  rounded_array.inject(:+) == rounded_sum
end