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: Utility 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'
DEFAULT_BASE_YEAR =

The default base year

Since:

  • 0.2.0

2000
DEFAULT_SPAN =

The default span in years

Since:

  • 0.2.0

100
HOUR =

Hour in terms of days

Since:

  • 0.2.0

Rational(1,24)
MINUTE =

Minute in terms of days

Since:

  • 0.2.0

Rational(1,1440)
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 =

Represents the days of the week to be used in applying working and resting patterns. Values exist for each day of the week as well as for the weekend (Saturday and Sunday), the week (Monday to Friday) and all days in the week.

Since:

  • 0.0.1

{:sun => [0],:mon => [1], :tue => [2], :wed => [3], :thu => [4], :fri => [5], :sat => [6],
:weekday => [1,2,3,4,5],
:weekend => [0,6],
:all => [0,1,2,3,4,5,6]}
VERSION =
'0.4.0'

Class Method Summary collapse

Class Method Details

.clearObject

Convenience method to delete all Workpatterns.

Since:

  • 0.2.0


131
132
133
# File 'lib/workpattern.rb', line 131

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


145
146
147
# File 'lib/workpattern.rb', line 145

def self.clock(hour,min)
  return 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


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

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


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

def self.get(name)
  return 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.

  • span (Integer) (defaults to: DEFAULT_SPAN)

    Workpattern spans this number of years ending on 31st December.

Returns:

Raises:

  • (NameError)

    when trying to create a Workpattern with a name that already exists

Since:

  • 0.2.0


92
93
94
# File 'lib/workpattern.rb', line 92

def self.new(name=DEFAULT_WORKPATTERN_NAME, base=DEFAULT_BASE_YEAR, span=DEFAULT_SPAN)
  return 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


102
103
104
# File 'lib/workpattern.rb', line 102

def self.to_a()
  return Workpattern.to_a
end