class Nanakshahi
Nanakshahi
Calendar date based on research by Pal Singh Purewal @author Arvinder Singh @see panjabilab.com Panjabi Lab @since 0.1.0 @attr_reader [Integer] year Year part of Nanakshahi
date object @attr_reader [Integer] month Month part of Nanakshahi
date object @attr_reader [Integer] day Day part of Nanakshahi
date object
Constants
- VERSION
Attributes
Public Class Methods
Creates new instance of Nanakshahi
@param [Integer] year Year part of Nanakshahi
date @param [Integer] month Month part of Nanakshahi
date @param [Integer] day Day part of Nanakshahi
date
# File lib/nanakshahi.rb, line 35 def initialize(year = 1, month = 1, day = 1) @day = day @month = month @year = year end
Returns today as a Nanakshahi
date
# File lib/nanakshahi.rb, line 24 def self.today Date.today.to_nanakshahi end
Public Instance Methods
Returns if a Gurpurab falls on this day
@return [Boolean] True if it is a Gurpurab
# File lib/nanakshahi.rb, line 97 def gurpurab? !! GURPURB_IN_NS_MONTHS[month][day] end
Returns gurpurabs on the day or nil
return [Array] All Gurpurbs that fall on the day
# File lib/nanakshahi.rb, line 104 def gurpurabs GURPURB_IN_NS_MONTHS[month][day] end
Checks Nanakshahi
leap year
@return [Boolean] True if Nanakshahi
year's Phagun has 31 days
# File lib/nanakshahi.rb, line 69 def leap? self.to_gregorian.leap? end
Converts Nanakshahi
to Gregorian date
@return [Date] Converts nanakshahi into corresponding gregorian# as Date
object
# File lib/nanakshahi.rb, line 44 def to_gregorian gyear = year + 1468 nanakshahi_months = self.class.date_grid(gyear) nanakshahi_months[month - 1][day - 1] end
Gurmukhi String representation of Nanakshahi
object
@return [String] Gurmukhi String representation of Nanakshahi
# File lib/nanakshahi.rb, line 61 def to_gurmukhi era = year < 1 ? :ਧੁੰਦਕਾਲ : :ਨਾਨਕਸ਼ਾਹੀ "#{panjabi_numerals(day)} #{I18n.t(:nanakshahi_months, locale: :pa)[month]}, #{panjabi_numerals(year_zero_correction(year))} #{era}" end
String representation of Nanakshahi
object
@return [String] String representation of Nanakshahi
# File lib/nanakshahi.rb, line 53 def to_s era = year < 1 ? :Dhundkaal : :Nanakshahi "#{day} #{I18n.t(:nanakshahi_months)[month]}, #{year_zero_correction(year)} #{era}" end
Returns the day of the week in Gurmukhi
@return [String] Gurmukhi representation of day of week
# File lib/nanakshahi.rb, line 90 def vaar I18n.t(:day_names, locale: :pa)[wday] end
Return week of the day starting with Monday
@return [Integer] The day index of the week
# File lib/nanakshahi.rb, line 76 def wday self.to_gregorian.wday end
Returns the day of the week in English
@return [String] English representation of day of week
# File lib/nanakshahi.rb, line 83 def wday_name I18n.t(:day_names)[wday] end
Protected Instance Methods
Implementation of spaceship operator to enable comparision
@param [Nanakshahi] other Other object to compare with @return [Integer]
nil if not a Nanakshahi object -1 if self < other 0 if self == other 1 if self > other
@protected
# File lib/nanakshahi.rb, line 119 def <=>(other) return nil unless self.is_a?(Nanakshahi) && other.is_a?(Nanakshahi) if ((self.year < other.year) || (self.year == other.year && self.month < other.month) || (self.year == other.year && self.month == other.month && self.day < other.day)) return -1 elsif self.year == other.year && self.month == other.month && self.day == other.day return 0 else return 1 end end
Private Instance Methods
Converts english numerals to Gurmukhi
@param [Integer] number A numeric usually date @return [String] Panjabi representation of date @private
# File lib/nanakshahi.rb, line 149 def panjabi_numerals(number) number.to_s.chars.map { |digit| I18n.t(:digits, locale: :pa)[digit.to_i] }.join end
Considering no year 0 just like in Gregorian Year 1 Dhundkaal precedes 1 Nanakshahi
@param [Integer] dyear Year @return [Integer] Year corrected for year 0 @private
# File lib/nanakshahi.rb, line 140 def year_zero_correction(dyear) dyear < 1 ? dyear.abs + 1 : dyear.abs end