Class: ISO8601::Atom Abstract
- Inherits:
-
Object
- Object
- ISO8601::Atom
- Defined in:
- lib/iso8601/atoms.rb
Overview
This class is abstract.
A generic atom in a Duration
Instance Method Summary collapse
-
#factor ⇒ Object
The atom factor to compute the amount of seconds for the atom.
-
#initialize(atom, base = nil) ⇒ Atom
constructor
A new instance of Atom.
-
#to_i ⇒ Object
The integer representation of the atom.
-
#to_seconds ⇒ Object
The amount of seconds of the atom.
Constructor Details
#initialize(atom, base = nil) ⇒ Atom
Returns a new instance of Atom.
13 14 15 16 17 18 |
# File 'lib/iso8601/atoms.rb', line 13 def initialize(atom, base=nil) raise TypeError, "The atom argument for #{self.inspect} should be a Numeric value." unless atom.kind_of? Numeric raise TypeError, "The base argument for #{self.inspect} should be a ISO8601::DateTime instance or nil." unless base.kind_of? ISO8601::DateTime or base.nil? @atom = atom @base = base end |
Instance Method Details
#factor ⇒ Object
The atom factor to compute the amount of seconds for the atom
31 32 33 |
# File 'lib/iso8601/atoms.rb', line 31 def factor raise NotImplementedError, "The #factor method should be implemented for each subclass" end |
#to_i ⇒ Object
The integer representation of the atom
21 22 23 |
# File 'lib/iso8601/atoms.rb', line 21 def to_i @atom.to_i end |
#to_seconds ⇒ Object
The amount of seconds of the atom
26 27 28 |
# File 'lib/iso8601/atoms.rb', line 26 def to_seconds @atom * self.factor end |