class AIXM::D

Distance or length

@example

AIXM.d(123, :m)

Constants

UNITS

Attributes

dist[R]

@return [Float] distance

unit[R]

@return [Symbol] unit (see {UNITS})

Public Class Methods

new(dist, unit) click to toggle source
   # File lib/aixm/d.rb
30 def initialize(dist, unit)
31   self.dist, self.unit = dist, unit
32 end

Public Instance Methods

<=>(other) click to toggle source

@see Object#<=> @return [Integer]

   # File lib/aixm/d.rb
69 def <=>(other)
70   dist <=> other.send(:"to_#{unit}").dist
71 end
==(other) click to toggle source

@see Object#== @return [Boolean]

   # File lib/aixm/d.rb
75 def ==(other)
76   self.class === other  && (self <=> other).zero?
77 end
Also aliased as: eql?
dist=(value) click to toggle source
   # File lib/aixm/d.rb
44 def dist=(value)
45   fail(ArgumentError, "invalid dist") unless value.is_a?(Numeric) && value >= 0
46   @dist = value.to_f
47 end
eql?(other)
Alias for: ==
hash() click to toggle source

@see Object#hash @return [Integer]

   # File lib/aixm/d.rb
82 def hash
83   to_s.hash
84 end
inspect() click to toggle source

@return [String]

   # File lib/aixm/d.rb
35 def inspect
36   %Q(#<#{self.class} #{to_s}>)
37 end
to_s() click to toggle source

@return [String] human readable representation (e.g. “123 m”)

   # File lib/aixm/d.rb
40 def to_s
41   [dist, unit].join(' ')
42 end
unit=(value) click to toggle source
   # File lib/aixm/d.rb
49 def unit=(value)
50   fail(ArgumentError, "invalid unit") unless value.respond_to? :to_sym
51   @unit = value.to_sym.downcase
52   fail(ArgumentError, "invalid unit") unless UNITS.has_key? @unit
53 end