nepdate-patro 1.0.0.rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +9 -0
- data/LICENSE +21 -0
- data/NOTICE +31 -0
- data/README.md +18 -0
- data/lib/nepdate/patro/calendar_info.rb +65 -0
- data/lib/nepdate/patro/named.rb +50 -0
- data/lib/nepdate/patro/table.rb +1241 -0
- data/lib/nepdate/patro/version.rb +7 -0
- data/lib/nepdate/patro.rb +88 -0
- data/sig/nepdate-patro.rbs +58 -0
- metadata +74 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9b459e6f82b11e2c351e3d920a7ecc85ab0322905d925a6b32686428361a06d9
|
|
4
|
+
data.tar.gz: 125260e1c923b5bf0623891a2b537e2a40dcbea999aef226c636df1404a95ac7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9027e6bfb745b932cc8ab8b509ec4eaf2614713e06efbb829e8eafd036082642156d49da01ef6fc2e8f6b3950c0ee4a1a5af61cd75dab29f07e9cd3a005beae1
|
|
7
|
+
data.tar.gz: bc4bc4238031b957f64614bf69a891667aae84d549aa053c2f3c940614c6d130f63d1b053720e0c92c10f243f9466d108f24545f687fcab34fd71a2cecb4b72d
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 NepDate contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/NOTICE
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
NepDate for Ruby
|
|
2
|
+
|
|
3
|
+
This repository ports NepDate, the C# library by Raju Prasai and contributors
|
|
4
|
+
(https://github.com/RajuPrasai/NepDate), to Ruby. The calendar and patro data, the golden test
|
|
5
|
+
vectors and the behaviour this port follows all come from that library.
|
|
6
|
+
|
|
7
|
+
The calendar data in shared/data (data/calendar/, data/patro/) was extracted from
|
|
8
|
+
NepDate (https://github.com/RajuPrasai/NepDate, commit c6fff4f2f60ac01e31c086568320649627422ba1)
|
|
9
|
+
and is used under the MIT License:
|
|
10
|
+
|
|
11
|
+
MIT License
|
|
12
|
+
|
|
13
|
+
Copyright (c) 2023 NepDate and contributors
|
|
14
|
+
|
|
15
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
in the Software without restriction, including without limitation the rights
|
|
18
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
furnished to do so, subject to the following conditions:
|
|
21
|
+
|
|
22
|
+
The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
copies or substantial portions of the Software.
|
|
24
|
+
|
|
25
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# nepdate-patro
|
|
2
|
+
|
|
3
|
+
The patro (पात्रो, the Nepali almanac) for Ruby: tithi, public holidays and events for Bikram Sambat
|
|
4
|
+
dates. It depends on `nepdate`; the core gem has no almanac data.
|
|
5
|
+
|
|
6
|
+
```ruby
|
|
7
|
+
require "nepdate"
|
|
8
|
+
require "nepdate/patro"
|
|
9
|
+
|
|
10
|
+
day = NepDate::Patro.info(NepDate::Date.from_bs(2081, 2, 15))
|
|
11
|
+
puts day.tithi.english # Panchami
|
|
12
|
+
puts day.public_holiday? # true
|
|
13
|
+
puts day.events_en # Republic Day
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The data covers BS 2077-01-01 to 2084-08-20 and is informational, not an official calendar. It is
|
|
17
|
+
compiled into constant tables, so nothing is read at run time. The full API is in the repository's
|
|
18
|
+
[docs/API.md](https://github.com/sanamhub/nepdate-ruby/blob/main/docs/API.md).
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module NepDate
|
|
4
|
+
module Patro
|
|
5
|
+
# Everything the patro knows about one BS date. A date without data has a +nil+ tithi, a
|
|
6
|
+
# false holiday flag and an empty event list; +info+ never fails.
|
|
7
|
+
class CalendarInfo
|
|
8
|
+
attr_reader :tithi, :events
|
|
9
|
+
|
|
10
|
+
def initialize(tithi: nil, public_holiday: false, events: [])
|
|
11
|
+
@tithi = tithi
|
|
12
|
+
@public_holiday = public_holiday ? true : false
|
|
13
|
+
@events = events.freeze
|
|
14
|
+
freeze
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def public_holiday?
|
|
18
|
+
@public_holiday
|
|
19
|
+
end
|
|
20
|
+
alias_method :is_public_holiday, :public_holiday?
|
|
21
|
+
alias_method :holiday?, :public_holiday?
|
|
22
|
+
|
|
23
|
+
def tithi_np
|
|
24
|
+
tithi&.nepali || ""
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def tithi_en
|
|
28
|
+
tithi&.english || ""
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def events_np
|
|
32
|
+
events.map(&:nepali)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def events_en
|
|
36
|
+
events.map(&:english)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def to_h
|
|
40
|
+
{
|
|
41
|
+
tithi: tithi&.to_h,
|
|
42
|
+
public_holiday: public_holiday?,
|
|
43
|
+
events: events.map(&:to_h)
|
|
44
|
+
}
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def ==(other)
|
|
48
|
+
other.is_a?(CalendarInfo) &&
|
|
49
|
+
tithi == other.tithi &&
|
|
50
|
+
public_holiday? == other.public_holiday? &&
|
|
51
|
+
events == other.events
|
|
52
|
+
end
|
|
53
|
+
alias_method :eql?, :==
|
|
54
|
+
|
|
55
|
+
def hash
|
|
56
|
+
[CalendarInfo, tithi, public_holiday?, events].hash
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def inspect
|
|
60
|
+
"#<NepDate::Patro::CalendarInfo tithi=#{tithi&.english.inspect} holiday=#{public_holiday?} " \
|
|
61
|
+
"events=#{events_en.inspect}>"
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module NepDate
|
|
4
|
+
module Patro
|
|
5
|
+
# A tithi or event name in both languages. +name+ selects one; +nepali+ and +english+ are
|
|
6
|
+
# always available.
|
|
7
|
+
class Named
|
|
8
|
+
attr_reader :nepali, :english
|
|
9
|
+
|
|
10
|
+
def initialize(nepali, english)
|
|
11
|
+
@nepali = String(nepali).freeze
|
|
12
|
+
@english = String(english).freeze
|
|
13
|
+
freeze
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def name(lang: :en)
|
|
17
|
+
(Lang.coerce(lang) == :ne) ? nepali : english
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def to_h
|
|
21
|
+
{np: nepali, en: english}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def ==(other)
|
|
25
|
+
other.is_a?(self.class) && nepali == other.nepali && english == other.english
|
|
26
|
+
end
|
|
27
|
+
alias_method :eql?, :==
|
|
28
|
+
|
|
29
|
+
def hash
|
|
30
|
+
[self.class, nepali, english].hash
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def to_s
|
|
34
|
+
english
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def inspect
|
|
38
|
+
"#<#{self.class} #{english.inspect} / #{nepali.inspect}>"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# A lunar day name.
|
|
43
|
+
class Tithi < Named
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# One almanac event, in file order when several share a day.
|
|
47
|
+
class Event < Named
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|