Class: Suprdate::Year

Inherits:
Unit
  • Object
show all
Defined in:
lib/suprdate/year.rb

Constant Summary collapse

MINIMUM_VALUE =

year when leap years were first standardized

1582
STRFTIME_STR =
'%Y'

Instance Attribute Summary collapse

Attributes inherited from Unit

#value

Instance Method Summary collapse

Methods inherited from Unit

<=>, #==, #hash, #new, significance, #to_s

Methods included from Utility::CleanConstantName

#name_plural, #name_singular, #to_sym

Instance Attribute Details

#day_factoryObject

Returns the value of attribute day_factory.



5
6
7
# File 'lib/suprdate/year.rb', line 5

def day_factory
  @day_factory
end

#month_factoryObject

Returns the value of attribute month_factory.



5
6
7
# File 'lib/suprdate/year.rb', line 5

def month_factory
  @month_factory
end

#week_definitionObject

Returns the value of attribute week_definition.



5
6
7
# File 'lib/suprdate/year.rb', line 5

def week_definition
  @week_definition
end

#week_factoryObject

Returns the value of attribute week_factory.



5
6
7
# File 'lib/suprdate/year.rb', line 5

def week_factory
  @week_factory
end

Instance Method Details

#+(increase) ⇒ Object



32
# File 'lib/suprdate/year.rb', line 32

def +(increase) new(@value + increase) end

#-(decrease) ⇒ Object



33
# File 'lib/suprdate/year.rb', line 33

def -(decrease) new(@value - decrease) end

#<=>(operand) ⇒ Object



21
22
23
24
25
# File 'lib/suprdate/year.rb', line 21

def <=>(operand)
  return -1 if operand == Infinity
  operand = operand.year
  @value - operand.value
end

#day(*args) ⇒ Object



37
# File 'lib/suprdate/year.rb', line 37

def day(*args) month(1).day(*args) end

#daysObject



36
# File 'lib/suprdate/year.rb', line 36

def days() months.map { |m| m.days }.flatten end

#inspectObject



38
# File 'lib/suprdate/year.rb', line 38

def inspect() @value.to_s end

#leap?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
# File 'lib/suprdate/year.rb', line 43

def leap?
  return true  if @value % 400 == 0
  return false if @value % 100 == 0
  return true  if @value % 4   == 0
  false
end

#month(*indices) ⇒ Object Also known as: []



27
28
29
30
# File 'lib/suprdate/year.rb', line 27

def month(*indices)
  indices = [1] if indices.empty?
  Utility::disarray(indices.map { |i| new_month(i) })
end

#monthsObject



35
# File 'lib/suprdate/year.rb', line 35

def months() MONTH_RANGE.to_a.map { |i| new_month(i) }  end

#since(year) ⇒ Object



40
# File 'lib/suprdate/year.rb', line 40

def since(year) @value - year.value end

#succObject



34
# File 'lib/suprdate/year.rb', line 34

def succ() self + 1 end

#until(year) ⇒ Object



41
# File 'lib/suprdate/year.rb', line 41

def until(year) year.value - @value end

#yearObject



39
# File 'lib/suprdate/year.rb', line 39

def year() self end