Module: PDGRound

Defined in:
lib/pdground/pdground.rb,
lib/pdground/version.rb

Overview

PDGRound module

Constant Summary collapse

VERSION =
'0.1.4'

Class Method Summary collapse

Class Method Details

.round(args) ⇒ Object

Main function for the rounding



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/pdground/pdground.rb', line 6

def self.round(args)
  unless args[:meas] && args[:unc]
    raise ArgumentError 'To round a value you need a value and an
                         uncertainty (:val and :unc parameters)'
  end
  args.each { |k, v| args[k] = v.to_s if v.is_a? Numeric }
  dig = digits(args[:unc]).to_i
  return round_to(args, 2) if dig < 355
  return round_to(args, 1) if dig < 950
  round_to_up(args)
end