Class: IfcDate

Inherits:
Object
  • Object
show all
Extended by:
IfcDateClassMethods
Defined in:
lib/ifc_date.rb,
lib/ifc_date/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

DAYNAMES =
Date::DAYNAMES + ['Starday']
ABBR_DAYNAMES =
Date::ABBR_DAYNAMES + ['Sta']
MONTHNAMES =
Date::MONTHNAMES.dup.insert(6, 'Sol')
ABBR_MONTHNAMES =
Date::ABBR_MONTHNAMES.dup.insert(6, 'Sol')
VERSION =
"0.1.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from IfcDateClassMethods

is_leap_year?, memoize

Constructor Details

#initialize(day_of_year = nil, year = nil) ⇒ IfcDate

Returns a new instance of IfcDate.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ifc_date.rb', line 18

def initialize(day_of_year = nil, year = nil)
  unless year
    date = Date.today
    year = date.year
    day_of_year ||= date.yday
  end

  day_of_year ||= date.yday

  @day_of_year = day_of_year
  @year        = year
end

Instance Attribute Details

#day_of_yearObject (readonly) Also known as: yday

Returns the value of attribute day_of_year.



11
12
13
# File 'lib/ifc_date.rb', line 11

def day_of_year
  @day_of_year
end

#yearObject (readonly)

Returns the value of attribute year.



11
12
13
# File 'lib/ifc_date.rb', line 11

def year
  @year
end

Instance Method Details

#abbr_day_nameObject



93
94
95
# File 'lib/ifc_date.rb', line 93

def abbr_day_name
  ABBR_DAYNAMES[day_of_week]
end

#abbr_month_nameObject



101
102
103
# File 'lib/ifc_date.rb', line 101

def abbr_month_name
  ABBR_MONTHNAMES[month_of_year]
end

#day_nameObject



89
90
91
# File 'lib/ifc_date.rb', line 89

def day_name
  DAYNAMES[day_of_week]
end

#day_of_monthObject Also known as: mday



74
75
76
77
# File 'lib/ifc_date.rb', line 74

def day_of_month
  return 29 if starday?
  day_of_year_divmod_twenty_eight[1] + 1
end

#month_nameObject



97
98
99
# File 'lib/ifc_date.rb', line 97

def month_name
  MONTHNAMES[month_of_year]
end

#month_of_yearObject Also known as: month

Return the month in index of the year. NOTE Januari will be 1, so different indexing thant the wday



82
83
84
85
86
# File 'lib/ifc_date.rb', line 82

def month_of_year
  return 13 if day_of_year > 364 # prevent 14
  return 6 if leap_year? && day_of_year == 169
  day_of_year_divmod_twenty_eight[0] + 1
end