Module: Workpattern

Defined in:
lib/workpattern.rb,
lib/workpattern/week.rb,
lib/workpattern/clock.rb,
lib/workpattern/version.rb,
lib/workpattern/workpattern.rb,
lib/workpattern/utility/base.rb

Overview

workpattern.rb - date calculation library that takes into account patterns of working and resting time and is aimed at supporting scheduling applications such as critical path analysis.

Author: Barrie Callender 2011

Documentation: Barrie Callender <[email protected]>

Defined Under Namespace

Modules: Base Classes: Clock, Week, Workpattern

Constant Summary collapse

WORKING_HOUR =

Represents a full working hour

Since:

  • 0.2.0

2**60 - 1
RESTING_HOUR =

Represents a full resting hour

Since:

  • 0.2.0

0
DEFAULT_WORKPATTERN_NAME =

The default workpattern name

Since:

  • 0.2.0

'default'.freeze
DEFAULT_BASE_YEAR =

The default base year

Since:

  • 0.2.0

2000
DEFAULT_SPAN =

The default span in years

Since:

  • 0.2.0

100
MINUTE =

Minute in terms of seconds

60
HOUR =

Hour interms od seconds

MINUTE * 60
DAY =

Day in terms of seconds

HOUR * 24
FIRST_TIME_IN_DAY =

Earliest or first time in the day

Since:

  • 0.0.1

Clock.new(0, 0)
LAST_TIME_IN_DAY =

Latest or last time in the day

Since:

  • 0.0.1

Clock.new(23, 59)
WORK =

Specifies a working pattern

Since:

  • 0.0.1

1
REST =

Specifies a resting pattern

Since:

  • 0.0.1

0
DAYNAMES =
daynames.freeze
VERSION =
'0.5.0'.freeze

Class Method Summary collapse

Class Method Details

.clearObject

Convenience method to delete all Workpatterns.

Since:

  • 0.2.0



141
142
143
# File 'lib/workpattern.rb', line 141

def self.clear
  Workpattern.clear
end

.clock(hour, min) ⇒ Clock

Convenience method to create a Clock object. This can be used for specifying times if you don’t want to create a DateTime object

Parameters:

  • hour (Integer)

    the number of hours.

  • min (Integer)

    the number of minutes

Returns:

See Also:

Since:

  • 0.2.0



155
156
157
# File 'lib/workpattern.rb', line 155

def self.clock(hour, min)
  Clock.new(hour, min)
end

.delete(name) ⇒ Object

Convenience method to delete the named Workpattern

Parameters:

  • name (String)

    The name of the Workpattern to be deleted.

Since:

  • 0.2.0



133
134
135
# File 'lib/workpattern.rb', line 133

def self.delete(name)
  Workpattern.delete(name)
end

.get(name) ⇒ Workpattern

Covenience method to obtain an existing Workpattern

Parameters:

  • name (String)

    The name of the Workpattern to retrieve.

Returns:

Since:

  • 0.2.0



123
124
125
# File 'lib/workpattern.rb', line 123

def self.get(name)
  Workpattern.get(name)
end

.new(name = DEFAULT_WORKPATTERN_NAME, base = DEFAULT_BASE_YEAR, span = DEFAULT_SPAN) ⇒ Workpattern

Covenience method to obtain a new Workpattern

A negative span counts back from the base year

Parameters:

  • name (String) (defaults to: DEFAULT_WORKPATTERN_NAME)

    Every workpattern has a unique name.

  • base (Integer) (defaults to: DEFAULT_BASE_YEAR)

    Workpattern starts on the 1st January of this year.

  • number (Integer)

    of years ending on 31st December.

Returns:

Raises:

  • (NameError)

    creating a Workpattern with a name that already exists

Since:

  • 0.2.0



99
100
101
102
103
# File 'lib/workpattern.rb', line 99

def self.new(name = DEFAULT_WORKPATTERN_NAME,
             base = DEFAULT_BASE_YEAR,
             span = DEFAULT_SPAN)
  Workpattern.new(name, base, span)
end

.to_aArray

Covenience method to obtain an Array of all the known Workpattern objects

Returns:

  • (Array)

    all Workpattern objects

Since:

  • 0.2.0



112
113
114
# File 'lib/workpattern.rb', line 112

def self.to_a
  Workpattern.to_a
end