Class: IfcDate

Inherits:
Object
  • Object
show all
Extended by:
IfcDateClassMethods
Includes:
IfcDateInstanceMethods
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.2.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from IfcDateClassMethods

is_leap_year?, memoize

Methods included from IfcDateInstanceMethods

#clear_memoization_results

Constructor Details

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

Returns a new instance of IfcDate.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ifc_date.rb', line 22

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.



14
15
16
# File 'lib/ifc_date.rb', line 14

def day_of_year
  @day_of_year
end

#yearObject (readonly)

Returns the value of attribute year.



14
15
16
# File 'lib/ifc_date.rb', line 14

def year
  @year
end

Instance Method Details

#abbr_day_nameObject



104
105
106
# File 'lib/ifc_date.rb', line 104

def abbr_day_name
  ABBR_DAYNAMES[day_of_week]
end

#abbr_month_nameObject



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

def abbr_month_name
  ABBR_MONTHNAMES[month_of_year]
end

#day_nameObject



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

def day_name
  DAYNAMES[day_of_week]
end

#day_of_monthObject Also known as: mday



86
87
88
89
# File 'lib/ifc_date.rb', line 86

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

#inspectObject Also known as: to_s



116
117
118
# File 'lib/ifc_date.rb', line 116

def inspect
  "#{year.to_s}-#{month_of_year.to_s.rjust(2, '0')}-#{day_of_month.to_s}"
end

#month_nameObject



108
109
110
# File 'lib/ifc_date.rb', line 108

def month_name
  MONTHNAMES[month_of_year]
end

#month_of_yearObject Also known as: month

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



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

def month_of_year
  # The min operation if for the year day, which would be 14, but is appended to month 13
  [day_of_year_divmod_twenty_eight[0] + 1, 13].min
end