Class: Zmanim::HebrewCalendar::HebrewDateFormatter

Inherits:
Object
  • Object
show all
Extended by:
Util::TextHelper
Includes:
Util::HebrewNumericFormatter
Defined in:
lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb

Constant Summary collapse

HEBREW_OMER_PREFIX =
'ב'
FORMATTED_DAYS_OF_WEEK =
{
  transliterated: Date::DAYNAMES[0..-2] + ['Shabbos'],
  hebrew: %w(ראשון שני שלישי רביעי חמישי ששי שבת)
}
FORMATTED_MONTHS =
{
    transliterated: Zmanim::HebrewCalendar::JewishCalendar::MONTHS.each_with_object({}){|m, h|
      h[m] = titleize(m)
    }.merge(adar_i: 'Adar I', adar_ii: 'Adar II'),
    hebrew: {
        nissan:   'ניסן',
        iyar:     'אייר',
        sivan:    'סיון',
        tammuz:   'תמוז',
        av:       'אב',
        elul:     'אלול',
        tishrei:  'תשרי',
        cheshvan: 'חשון',
        kislev:   'כסלו',
        teves:    'טבת',
        shevat:   'שבט',
        adar:     'אדר',
        adar_i:   'אדר א',
        adar_ii:  'אדר ב'
    }
}
FORMATTED_SIGNIFICANT_DAYS =
{
    transliterated: Zmanim::HebrewCalendar::JewishCalendar::SIGNIFICANT_DAYS.each_with_object({}){|d, h|
      h[d] = titleize(d)
    }.merge(tzom_gedalyah: 'Fast of Gedalyah', tenth_of_teves: 'Tenth of Teves', tu_beshvat: "Tu B'Shvat",
            taanis_esther: 'Fast of Esther', seventeen_of_tammuz: 'Seventeenth of Tammuz',
            tisha_beav: "Tisha B'Av", tu_beav: "Tu B'Av", yom_hashoah: 'Yom HaShoah', yom_haatzmaut: "Yom Ha'atzmaut"),
    hebrew: {
        erev_rosh_hashana:   'ערב ראש השנה',
        rosh_hashana:        'ראש השנה',
        tzom_gedalyah:       'צום גדליה',
        erev_yom_kippur:     'ערב יום כיפור',
        yom_kippur:          'יום כיפור',
        erev_succos:         'ערב סוכות',
        succos:              'סוכות',
        chol_hamoed_succos:  'חול המועד סוכות',
        hoshana_rabbah:      'הושענה רבה',
        shemini_atzeres:     'שמיני עצרת',
        simchas_torah:       'שמחת תורה',
        chanukah:            'חנוכה',
        tenth_of_teves:      'עשרה בטבת',
        tu_beshvat:          'ט״ו בשבט',
        taanis_esther:       'תענית אסתר',
        purim:               'פורים',
        shushan_purim:       'שושן פורים',
        purim_katan:         'פורים קטן',
        shushan_purim_katan: 'שושן פורים קטן',
        erev_pesach:         'ערב פסח',
        pesach:              'פסח',
        chol_hamoed_pesach:  'חול המועד פסח',
        pesach_sheni:        'פסח שני',
        erev_shavuos:        'ערב שבועות',
        shavuos:             'שבועות',
        seventeen_of_tammuz: 'שבעה עשר בתמוז',
        tisha_beav:          'תשעה באב',
        tu_beav:             'ט״ו באב',
        yom_hashoah:         'יום השואה',
        yom_hazikaron:       'יום הזכרון',
        yom_haatzmaut:       'יום העצמאות',
        yom_yerushalayim:    'יום ירושלים',
    }
}
FORMATTED_SIGNIFICANT_TEFILOS =
{
    transliterated: Zmanim::HebrewCalendar::JewishCalendar::SIGNIFICANT_TEFILOS.each_with_object({}){|d, h|
      h[d] = titleize(d)
    }.merge(begin_mashiv_haruach: 'Mashiv Haruach (beginning Mussaf)',
            end_mashiv_haruach:   'Mashiv Haruach (ending Mussaf)',
            begin_morid_hatal:    'Morid Hatal (beginning Mussaf)'),
    hebrew: {
        yaaleh_veyavo:        'יעלה ויבא',
        al_hanissim:          'על הנסים',
        begin_mashiv_haruach: 'משיב הרוח (מתחילים במוסף)',
        end_mashiv_haruach:   'משיב הרוח (מסיימים במוסף)',
        mashiv_haruach:       'משיב הרוח',
        begin_morid_hatal:    'מוריד הטל (מתחילים במוסף)',
        morid_hatal:          'מוריד הטל',
        vesein_tal_umatar:    'ותן טל ומטר',
        vesein_beracha:       'ותן ברכה',
        atah_yatzarta:        'אתה יצרת',
        borchi_nafshi:        'ברכי נפשי',
    }
}
FORMATTED_SIGNIFICANT_SHABBOSOS =
{
    transliterated: Zmanim::HebrewCalendar::JewishCalendar::SIGNIFICANT_SHABBOS.each_with_object({}){|d, h|
      h[d] = titleize(d)
    },
    hebrew: {
        parshas_shekalim:  'פרשת שקלים',
        parshas_zachor:    'פרשת זכור',
        parshas_parah:     'פרשת פרה',
        parshas_hachodesh: 'פרשת החדש',
        shabbos_hagadol:   'שבת הגדול',
        shabbos_shuva:     'שבת שובה',
    }
}

Constants included from Util::HebrewNumericFormatter

Util::HebrewNumericFormatter::GERESH, Util::HebrewNumericFormatter::GERSHAYIM

Instance Attribute Summary collapse

Attributes included from Util::HebrewNumericFormatter

#use_geresh_gershayim

Instance Method Summary collapse

Methods included from Util::TextHelper

titleize

Constructor Details

#initializeHebrewDateFormatter

Returns a new instance of HebrewDateFormatter.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 118

def initialize
  super  # hebrew numeric formatter
  @long_week_format = true
  @transliterated_days_of_week = FORMATTED_DAYS_OF_WEEK[:transliterated]
  @transliterated_months = FORMATTED_MONTHS[:transliterated]
  @transliterated_significant_days = FORMATTED_SIGNIFICANT_DAYS[:transliterated]
  @transliterated_significant_tefilos = FORMATTED_SIGNIFICANT_TEFILOS[:transliterated]
  @transliterated_significant_shabbosos = FORMATTED_SIGNIFICANT_SHABBOSOS[:transliterated]
  @hebrew_days_of_week = FORMATTED_DAYS_OF_WEEK[:hebrew]
  @hebrew_months = FORMATTED_MONTHS[:hebrew]
  @hebrew_significant_days = FORMATTED_SIGNIFICANT_DAYS[:hebrew]
  @hebrew_significant_tefilos = FORMATTED_SIGNIFICANT_TEFILOS[:hebrew]
  @hebrew_significant_shabbosos = FORMATTED_SIGNIFICANT_SHABBOSOS[:hebrew]
  @hebrew_omer_prefix = HEBREW_OMER_PREFIX
end

Instance Attribute Details

#hebrew_days_of_weekObject

Returns the value of attribute hebrew_days_of_week.



7
8
9
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 7

def hebrew_days_of_week
  @hebrew_days_of_week
end

#hebrew_formatObject

Returns the value of attribute hebrew_format.



7
8
9
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 7

def hebrew_format
  @hebrew_format
end

#hebrew_monthsObject

Returns the value of attribute hebrew_months.



7
8
9
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 7

def hebrew_months
  @hebrew_months
end

#hebrew_omer_prefixObject

Returns the value of attribute hebrew_omer_prefix.



7
8
9
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 7

def hebrew_omer_prefix
  @hebrew_omer_prefix
end

#hebrew_significant_daysObject

Returns the value of attribute hebrew_significant_days.



7
8
9
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 7

def hebrew_significant_days
  @hebrew_significant_days
end

#hebrew_significant_shabbososObject

Returns the value of attribute hebrew_significant_shabbosos.



7
8
9
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 7

def hebrew_significant_shabbosos
  @hebrew_significant_shabbosos
end

#hebrew_significant_tefilosObject

Returns the value of attribute hebrew_significant_tefilos.



7
8
9
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 7

def hebrew_significant_tefilos
  @hebrew_significant_tefilos
end

#long_week_formatObject

Returns the value of attribute long_week_format.



7
8
9
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 7

def long_week_format
  @long_week_format
end

#transliterated_days_of_weekObject

Returns the value of attribute transliterated_days_of_week.



7
8
9
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 7

def transliterated_days_of_week
  @transliterated_days_of_week
end

#transliterated_monthsObject

Returns the value of attribute transliterated_months.



7
8
9
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 7

def transliterated_months
  @transliterated_months
end

#transliterated_significant_daysObject

Returns the value of attribute transliterated_significant_days.



7
8
9
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 7

def transliterated_significant_days
  @transliterated_significant_days
end

#transliterated_significant_shabbososObject

Returns the value of attribute transliterated_significant_shabbosos.



7
8
9
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 7

def transliterated_significant_shabbosos
  @transliterated_significant_shabbosos
end

#transliterated_significant_tefilosObject

Returns the value of attribute transliterated_significant_tefilos.



7
8
9
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 7

def transliterated_significant_tefilos
  @transliterated_significant_tefilos
end

#use_long_hebrew_yearsObject

Returns the value of attribute use_long_hebrew_years.



7
8
9
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 7

def use_long_hebrew_years
  @use_long_hebrew_years
end

Instance Method Details

#format(date) ⇒ Object



134
135
136
137
138
139
140
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 134

def format(date)
  if hebrew_format
    format_hebrew_number(date.jewish_day) + ' ' + format_month(date) + ' ' + format_hebrew_number(date.jewish_year)
  else
    "#{date.jewish_day} #{format_month(date)}, #{date.jewish_year}"
  end
end

#format_day_of_week(date) ⇒ Object



146
147
148
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 146

def format_day_of_week(date)
  format_day_of_week_from_number(date.day_of_week)
end

#format_hebrew_number(number) ⇒ Object



150
151
152
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 150

def format_hebrew_number(number)
  super(number, use_long_hebrew_years)
end

#format_kviah(year) ⇒ Object



182
183
184
185
186
187
188
189
190
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 182

def format_kviah(year)
  date = year.is_a?(Numeric) ? Zmanim::HebrewCalendar::JewishDate.new(year, 7, 1) : year
  kviah = date.cheshvan_kislev_kviah
  rosh_hashana_day = date.day_of_week
  kviah_glyph = {chaseirim: 'ח', kesidran: 'כ', shelaimim: 'ש'}[kviah]
  date.jewish_month = 1
  pesach_day = date.day_of_week
  "#{format_hebrew_number(rosh_hashana_day)}#{kviah_glyph}#{format_hebrew_number(pesach_day)}".delete(GERESH)
end

#format_month(date) ⇒ Object



142
143
144
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 142

def format_month(date)
  format_month_from_name(date.jewish_month_name, date.jewish_leap_year?)
end

#format_omer(calendar) ⇒ Object



173
174
175
176
177
178
179
180
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 173

def format_omer(calendar)
  return '' unless number = calendar.day_of_omer
  if hebrew_format
    format_hebrew_number(number) + ' ' + hebrew_omer_prefix + 'עומר'
  else
    number == 33 ? 'Lag BaOmer' : "Omer #{number}"
  end
end

#format_rosh_chodesh(calendar) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 161

def format_rosh_chodesh(calendar)
  return '' unless calendar.rosh_chodesh? || calendar.erev_rosh_chodesh?
  month = calendar.jewish_month
  day = calendar.jewish_day
  if day != 1
    month += 1
    month = 1 if month > calendar.months_in_jewish_year
  end
  month_name = calendar.jewish_month_name(month)
  formatted_rosh_chodesh(calendar.erev_rosh_chodesh?) + ' ' + format_month_from_name(month_name, calendar.jewish_leap_year?)
end

#format_significant_day(calendar) ⇒ Object



154
155
156
157
158
159
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 154

def format_significant_day(calendar)
  sd = calendar.significant_day
  return '' unless sd
  prefix = (day_number = calendar.day_of_chanukah) ? formatted_number(day_number) + ' ' : ''
  prefix + formatted_significant_day(sd)
end

#format_significant_shabbos(calendar) ⇒ Object



201
202
203
204
205
206
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 201

def format_significant_shabbos(calendar)
  return '' unless shabbos = calendar.significant_shabbos
  hebrew_format ?
      hebrew_significant_shabbosos[shabbos] :
      transliterated_significant_shabbosos[shabbos]
end

#format_tefilah_additions(calendar, customs = {walled_city: false, nusach: :ashkenaz}) ⇒ Object



192
193
194
195
196
197
198
199
# File 'lib/zmanim/hebrew_calendar/hebrew_date_formatter.rb', line 192

def format_tefilah_additions(calendar, customs={walled_city: false, nusach: :ashkenaz})
  additions = calendar.tefilah_additions(walled_city: customs[:walled_city], nusach: customs[:nusach])
  additions.map do |addition|
    hebrew_format ?
      hebrew_significant_tefilos[addition] :
      transliterated_significant_tefilos[addition]
  end
end