Module: Unit::Comparable

Included in:
ComposedUnit, SimpleUnit
Defined in:
lib/unitmanager/simple_unit.rb

Overview

Adds comparing capabilities to unit implementations

Instance Method Summary collapse

Instance Method Details

#compatible?(other) ⇒ Boolean

Two units are compatible if they have same hierarchy base Example :cm is compatible with :in, since they both based on :mm

Returns:

  • (Boolean)


8
9
10
11
12
13
14
# File 'lib/unitmanager/simple_unit.rb', line 8

def compatible? (other)
  return false if other == nil
  return false unless other.respond_to?(:h_base)

  h_base[:dividends].same?(other.h_base[:dividends]) &&
  h_base[:divisors].same?(other.h_base[:divisors])
end

#contains?(other) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
# File 'lib/unitmanager/simple_unit.rb', line 16

def contains? (other)
  return false if other == nil
  return false unless other.respond_to?(:h_base)

  h_base[:dividends].contains?(other.h_base[:dividends]) &&
  h_base[:divisors].contains?(other.h_base[:divisors])
end