zmanim 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f7a1368c46f18f412f39609c0d076d14e9786a5
4
- data.tar.gz: f74bde128ee6b5131e1f55ede44feff17ac853f3
3
+ metadata.gz: 3f1cc976587acbbfd1df9ee5cd4fa5fda1a87e79
4
+ data.tar.gz: 3769e3712e2161dc0298a4c4d2be922854b97d31
5
5
  SHA512:
6
- metadata.gz: cc70992c4c514e0ba3b77126dace5f4f216c9714b84bd4b5dbf0e80e14a1a994544e708f70c2e650e9aac5d125c3fd391bac4524318d8607fefc6ea874f55c5d
7
- data.tar.gz: a85bc156410ea7493f1156e5f100b6a83e5cdb2fe99f90835c2f3c56b80d41c8727c791820ecc088743d05c31817bcc6fe21ff292014fd1f0a5c93590a9a5bb0
6
+ metadata.gz: 7e5e8c962d601071f4f9fed2fe5d83129ef1fc06738e47a25805869874fc1bd2bc538531551d3cac703f246bca3ad4fa42b1d9fb47a64eeeb4365d028a4fed42
7
+ data.tar.gz: a39894be370c65758d39925861bcf19c2b108efe9c640001a80d771411692af9ec40b49f9e59006cf31be5aedbfe018d9c73aa9f409bb9e7edc95bf0555ba84c
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.2.0] - 2018-04-22
8
+ ### Added
9
+ - Pirkei Avos limudim calculation
10
+ - Support for explicit skip_unit (used by DafYomiYerushalmi)
11
+ - CHANGELOG (this file :) )
12
+ ### Changed
13
+ - Refactored skip_interval to generic limud detection
14
+ ### Fixed
15
+ - Cycle detection falsely identifies dates between cycle windows as belonging to a prior cycle
16
+ - Load sequence can't find Zmanim module when loaded externally
17
+
18
+ ## [0.1.0] - 2018-01-09 (Original release)
19
+ ### Added
20
+ - Port of KosherJava/zmanim library, primary functionality
21
+ - Limudim calculation framework
22
+ - Weekly Parsha, Tehillim (Month cycle), Mishna Yomis limudim calculation
@@ -1,6 +1,5 @@
1
1
  require 'tzinfo'
2
- Dir[File.dirname(__FILE__) + "/**/*.rb"].each {|file| require file }
3
2
 
4
- module Zmanim
5
- # Your code goes here...
6
- end
3
+ module Zmanim; end
4
+
5
+ Dir[File.dirname(__FILE__) + "/**/*.rb"].each {|file| require file }
@@ -143,6 +143,10 @@ module Zmanim::HebrewCalendar
143
143
  Zmanim::Limudim::Calculators::MishnaYomis.new.limud(self)
144
144
  end
145
145
 
146
+ def pirkei_avos
147
+ Zmanim::Limudim::Calculators::PirkeiAvos.new(in_israel: in_israel).limud(self)
148
+ end
149
+
146
150
  def tefilah_additions(walled_city: false, nusach: :ashkenaz)
147
151
  additions = []
148
152
  if mashiv_haruach_starts?
@@ -33,12 +33,8 @@ module Zmanim::Limudim::Calculators
33
33
  end
34
34
  end
35
35
 
36
- def unit_for_interval(units, interval)
37
- if matches_skip_day?(interval.start_date)
38
- Zmanim::Limudim::Unit.new('no_daf_today')
39
- else
40
- super
41
- end
36
+ def skip_unit
37
+ Zmanim::Limudim::Unit.new('no_daf_today')
42
38
  end
43
39
 
44
40
  def skip_interval?(interval)
@@ -0,0 +1,54 @@
1
+ require 'zmanim/limudim/limud_calculator'
2
+
3
+ module Zmanim::Limudim::Calculators
4
+ class PirkeiAvos
5
+ include Zmanim::Limudim::LimudCalculator
6
+
7
+ attr_reader :in_israel
8
+
9
+ def initialize(in_israel:false)
10
+ @in_israel = in_israel
11
+ end
12
+
13
+ def tiered_units?
14
+ false
15
+ end
16
+
17
+ def perpetual_cycle_anchor
18
+ Zmanim::Limudim::Anchor::DayOfYearAnchor.new(1, in_israel ? 22 : 23) # Day after Pesach
19
+ end
20
+
21
+ def default_units
22
+ @default_units ||= (1..6).to_a * 4 # 4 sub-cycles of 6 perakim, with the last sub-cycle being compressed as needed
23
+ end
24
+
25
+ def cycle_end_calculation
26
+ ->(start_date, _iteration) do
27
+ rosh_hashana = Zmanim::HebrewCalendar::JewishDate.new(start_date.jewish_year + 1, 7, 1)
28
+ rosh_hashana - rosh_hashana.day_of_week # last Shabbos before Rosh Hashanah
29
+ end
30
+ end
31
+
32
+ def interval_end_calculation
33
+ ->(cycle, start_date) do
34
+ start_date + (7 - start_date.day_of_week)
35
+ end
36
+ end
37
+
38
+ def skip_interval?(interval)
39
+ !in_israel && [interval.end_date.jewish_month, interval.end_date.jewish_day] == [3,7]
40
+ end
41
+
42
+ def cycle_units_calculation
43
+ ->(cycle) do
44
+ cycle_weeks = ((cycle.end_date - cycle.start_date + 1) / 7.0).ceil
45
+ # If the cycle starts on a Friday, outside of israel the 2nd day of Shavuos will fall on Shabbos
46
+ # and we lose one week in the pirkei avos cycle
47
+ cycle_weeks -=1 if !in_israel && cycle.start_date.day_of_week == 6
48
+ unit_count = default_units.length
49
+ compress_weeks = (unit_count - cycle_weeks) * 2
50
+ default_units.first(unit_count - compress_weeks) + default_units.last(compress_weeks).each_slice(2).to_a
51
+ end
52
+ end
53
+ end
54
+ end
@@ -5,14 +5,15 @@ module Zmanim::Limudim
5
5
  def limud(date)
6
6
  jewish_date = jewish_date(date)
7
7
  cycle = find_cycle(jewish_date)
8
- return nil unless cycle
8
+ return nil unless cycle && cycle.end_date >= date
9
9
  units = cycle_units_calculation.(cycle)
10
10
  interval = cycle.first_interval(interval_end_calculation)
11
11
  while !jewish_date.between?(interval.start_date, interval.end_date) do
12
- interval = interval.next(interval_end_calculation)
13
- while !jewish_date.between?(interval.start_date, interval.end_date) && skip_interval?(interval)
14
- interval = interval.skip(interval_end_calculation)
15
- end
12
+ interval = if skip_interval?(interval)
13
+ interval.skip(interval_end_calculation)
14
+ else
15
+ interval.next(interval_end_calculation)
16
+ end
16
17
  end
17
18
  unit = unit_for_interval(units, interval)
18
19
  Zmanim::Limudim::Limud.new(interval, unit)
@@ -79,10 +80,15 @@ module Zmanim::Limudim
79
80
  end
80
81
 
81
82
  def unit_for_interval(units, interval)
83
+ return skip_unit if skip_interval?(interval)
82
84
  return tiered_units_for_interval(units, interval) if tiered_units?
83
85
  Unit.new(*units[interval.iteration-1])
84
86
  end
85
87
 
88
+ def skip_unit
89
+ nil
90
+ end
91
+
86
92
  def skip_interval?(interval)
87
93
  false
88
94
  end
@@ -159,6 +159,12 @@ module Zmanim::Limudim
159
159
  prefix + limud.unit.render {|e| format_number(e) }
160
160
  end
161
161
 
162
+ def format_avos(limud)
163
+ return '' unless unit = (limud && limud.unit)
164
+ prefix = hebrew_format ? 'פרקי אבות ' : 'Pirkei Avos '
165
+ prefix + unit.render {|e| format_number(e) }
166
+ end
167
+
162
168
  private
163
169
 
164
170
  def format_number(number)
@@ -1,3 +1,3 @@
1
1
  module Zmanim
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zmanim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pinny Markowitz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-09 00:00:00.000000000 Z
11
+ date: 2018-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tzinfo
@@ -90,6 +90,7 @@ extra_rdoc_files: []
90
90
  files:
91
91
  - ".gitignore"
92
92
  - ".rspec"
93
+ - CHANGELOG.md
93
94
  - Gemfile
94
95
  - LICENSE
95
96
  - README.md
@@ -108,6 +109,7 @@ files:
108
109
  - lib/zmanim/limudim/calculators/daf_yomi_yerushalmi.rb
109
110
  - lib/zmanim/limudim/calculators/mishna_yomis.rb
110
111
  - lib/zmanim/limudim/calculators/parsha.rb
112
+ - lib/zmanim/limudim/calculators/pirkei_avos.rb
111
113
  - lib/zmanim/limudim/calculators/tehillim_monthly.rb
112
114
  - lib/zmanim/limudim/cycle.rb
113
115
  - lib/zmanim/limudim/interval.rb