Class: ISO8601::Atom Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/iso8601/atoms.rb

Overview

This class is abstract.

A generic atom in a Duration

Direct Known Subclasses

Days, Hours, Minutes, Months, Seconds, Weeks, Years

Instance Method Summary collapse

Constructor Details

#initialize(atom, base = nil) ⇒ Atom

Returns a new instance of Atom.

Parameters:

  • atom (Numeric)

    The atom value

  • base (ISO8601::DateTime, nil) (defaults to: nil)

    (nil) The base datetime to compute the atom factor.

Raises:

  • (TypeError)


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

#factorObject

The atom factor to compute the amount of seconds for the atom

Raises:

  • (NotImplementedError)


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_iObject

The integer representation of the atom



21
22
23
# File 'lib/iso8601/atoms.rb', line 21

def to_i
  @atom.to_i
end

#to_secondsObject

The amount of seconds of the atom



26
27
28
# File 'lib/iso8601/atoms.rb', line 26

def to_seconds
  @atom * self.factor
end