Module: Suprdate

Defined in:
lib/suprdate.rb,
lib/suprdate.rb,
lib/suprdate/day.rb,
lib/suprdate/year.rb,
lib/suprdate/month.rb,
lib/suprdate/builder.rb

Defined Under Namespace

Modules: Infinity, Utility Classes: Builder, DateConstructionError, Day, Month, Unit, Year

Constant Summary collapse

BASE_DIR =
File.expand_path(File.join(File.dirname(__FILE__), '..'))
LIB_DIR =
File.join(BASE_DIR,"lib")
DATE_NUM_PARTS_RANGE =

The number of possible parts that can make up either a year, month, or day

1..3
UNIT_NUM_PARTS =

The unit associated each each number of parts

[nil, :year, :month, :day]
UNITS =

All date units defined from most to least significant.

[Year, Month, Day]
WEEKDAYS_SYM_TO_I =
{
  :mon => 1, :tue => 2, :wed => 3, :thu => 4,
  :fri => 5, :sat => 6, :sun => 7
}
WEEKDAYS_AS_SYM =
[nil, :sun, :mon, :tue, :wed, :thu, :fri, :sat]
WEEKDAYS_AS_STR =
[
  nil, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'
]
WEEKDAY_RANGE =
1..7
MONTHS_SYM_TO_I =
{
  :jan => 1,    :feb => 2,    :mar => 3,
  :apr => 4,    :may => 5,    :jun => 6,
  :jul => 7,    :aug => 8,    :sep => 9,
  :oct => 10,   :nov => 11,   :dec => 12,
}
MONTHS_AS_SYM =
[
  nil, :jan, :feb, :mar, :apr, :may, :jun, :jul,
  :aug, :sep, :oct, :nov, :dec
]
MONTHS_AS_STR =
[
  nil, 'January', 'February', 'March', 'April',
  'May', 'June', 'July', 'August', 'September',
  'October', 'November', 'December'
]
NUM_MONTHS_IN_YEAR =
12
MONTH_RANGE =
1..NUM_MONTHS_IN_YEAR
NUM_DAYS_IN_MONTHS =
[nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
ORDINALS =
[nil, :first, :second, :third, :fourth, :fifth]
ORDINALS_SYM_TO_I =
{
  :first => 1, :second  => 2, :third  => 3, :fourth => 4, :fifth => 5,
  :sixth => 6, :seventh => 7, :eighth => 8, :ninth  => 9, :tenth => 10
}
DEFAULT_BUILDER =
Builder.new

Instance Method Summary collapse

Instance Method Details

#every(ordinal, list, &block) ⇒ Object

Filters the elements from a list by their index according to the specified ordinal. Ordinal may be specified as an integer or symbol (see ORDINALS). Results are provided either as a returned list or code block accepting a single parameter. If a block is given the return value becomes the original, unaltered, list.



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/suprdate.rb', line 52

def every(ordinal, list, &block)
  ordinal = ORDINALS_SYM_TO_I.fetch(ordinal) if ordinal.kind_of?(Symbol)
  rval = if block
    list
  else
    block = lambda { |x| rval << x }
    []
  end
  list.each_with_index do |value, index|
    block.call(value) if index % ordinal == 0
  end
  rval
end