Module: ISO8601::Atomic
- Includes:
- Comparable
- Defined in:
- lib/iso8601/atomic.rb
Instance Attribute Summary collapse
-
#atom ⇒ Object
readonly
Returns the value of attribute atom.
Instance Method Summary collapse
- #<=>(other) ⇒ -1, ...
- #eql?(other) ⇒ Boolean
- #hash ⇒ Fixnum
-
#to_f ⇒ Float
The float representation.
-
#to_i ⇒ Integer
The integer representation.
-
#to_s ⇒ String
Returns the ISO 8601 representation for the atom.
-
#valid_atom?(atom) ⇒ Boolean
Validates the atom is a Numeric.
- #valid_base?(base) ⇒ Boolean
-
#value ⇒ Numeric
The simplest numeric representation.
Instance Attribute Details
#atom ⇒ Object (readonly)
Returns the value of attribute atom.
5 6 7 |
# File 'lib/iso8601/atomic.rb', line 5 def atom @atom end |
Instance Method Details
#<=>(other) ⇒ -1, ...
44 45 46 47 48 |
# File 'lib/iso8601/atomic.rb', line 44 def <=>(other) return nil unless other.is_a?(self.class) to_f <=> other.to_f end |
#eql?(other) ⇒ Boolean
54 55 56 |
# File 'lib/iso8601/atomic.rb', line 54 def eql?(other) (hash == other.hash) end |
#hash ⇒ Fixnum
60 61 62 |
# File 'lib/iso8601/atomic.rb', line 60 def hash [atom, self.class].hash end |
#to_f ⇒ Float
The float representation
19 20 21 |
# File 'lib/iso8601/atomic.rb', line 19 def to_f atom.to_f end |
#to_i ⇒ Integer
The integer representation
11 12 13 |
# File 'lib/iso8601/atomic.rb', line 11 def to_i atom.to_i end |
#to_s ⇒ String
Returns the ISO 8601 representation for the atom
27 28 29 |
# File 'lib/iso8601/atomic.rb', line 27 def to_s value.zero? ? '' : "#{value}#{symbol}" end |
#valid_atom?(atom) ⇒ Boolean
Validates the atom is a Numeric
66 67 68 69 |
# File 'lib/iso8601/atomic.rb', line 66 def valid_atom?(atom) raise(ISO8601::Errors::TypeError, "The atom argument for #{self.class} should be a Numeric value.") \ unless atom.is_a?(Numeric) end |
#valid_base?(base) ⇒ Boolean
71 72 73 74 |
# File 'lib/iso8601/atomic.rb', line 71 def valid_base?(base) raise(ISO8601::Errors::TypeError, "The base argument for #{self.class} should be a ISO8601::DateTime instance or nil.") \ unless base.is_a?(ISO8601::DateTime) || base.nil? end |
#value ⇒ Numeric
The simplest numeric representation. If modulo equals 0 returns an integer else a float.
36 37 38 |
# File 'lib/iso8601/atomic.rb', line 36 def value (atom % 1).zero? ? atom.to_i : atom end |