Class: SmartRounding
- Inherits:
-
Object
- Object
- SmartRounding
- Defined in:
- lib/smart_rounding.rb
Instance Method Summary collapse
-
#initialize(array) ⇒ SmartRounding
constructor
A new instance of SmartRounding.
- #rounded_array ⇒ Object
- #rounded_sum ⇒ Object
- #rounds_equal? ⇒ Boolean
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_array ⇒ Object
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_sum ⇒ Object
6 7 8 |
# File 'lib/smart_rounding.rb', line 6 def rounded_sum array.inject(:+).round() end |
#rounds_equal? ⇒ Boolean
14 15 16 |
# File 'lib/smart_rounding.rb', line 14 def rounds_equal? rounded_array.inject(:+) == rounded_sum end |