calrom 0.1.0 → 0.2.0
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 +5 -5
- data/.travis.yml +13 -3
- data/CHANGELOG.md +24 -0
- data/README.md +57 -2
- data/Rakefile +5 -1
- data/calrom.gemspec +1 -1
- data/lib/calrom.rb +5 -0
- data/lib/calrom/cli.rb +8 -8
- data/lib/calrom/config.rb +17 -3
- data/lib/calrom/date_range.rb +72 -2
- data/lib/calrom/exceptions.rb +4 -0
- data/lib/calrom/formatter/easter.rb +16 -0
- data/lib/calrom/formatter/formatter.rb +1 -1
- data/lib/calrom/formatter/list.rb +8 -5
- data/lib/calrom/formatter/overview.rb +99 -0
- data/lib/calrom/highlighter/list.rb +6 -1
- data/lib/calrom/highlighter/no.rb +17 -0
- data/lib/calrom/highlighter/overview.rb +15 -0
- data/lib/calrom/option_parser.rb +130 -14
- data/lib/calrom/version.rb +1 -1
- metadata +12 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8080fbff35aedfe1af84126ea841c66f8f3a36a513bc89b4a5f2a736a7b3205f
|
4
|
+
data.tar.gz: c0ff3d64def3e7b227ba4f64e145e0c589c449ec516a04d82a2252d7d4456bf3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cf9192362ddd378d703835fab6861e72c8cfd080a7320207bf8e02366898f75152bc8b036709685f0008b5e1afea91b064e6b620f5dedc54e4f797ff0fa5a8e
|
7
|
+
data.tar.gz: cf71e5c86049312c0568d725e0d236e57e9ad0cd205f729f8740af0922d30a4f2f028548abfdc1bc69ee30fcc6fc23f4dc6278ceafce9ac6774a97af3f1abd11
|
data/.travis.yml
CHANGED
@@ -1,5 +1,15 @@
|
|
1
|
-
sudo: false
|
2
1
|
language: ruby
|
2
|
+
|
3
|
+
dist: trusty
|
4
|
+
|
5
|
+
# oldest supported and newest MRI
|
3
6
|
rvm:
|
4
|
-
- 2.
|
5
|
-
|
7
|
+
- 2.5.0
|
8
|
+
- 2.7.1
|
9
|
+
|
10
|
+
install: bundle install --jobs=3
|
11
|
+
|
12
|
+
script: bundle exec rake
|
13
|
+
|
14
|
+
git:
|
15
|
+
depth: 3
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [0.2.0] 2020-01-14
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- cal-like view (is now default for month, year and date range listing)
|
8
|
+
- support more cal-like ways of specifying date range
|
9
|
+
- month argument `calrom MONTH YEAR` (as an alternative to month option `cal -m MONTH YEAR`)
|
10
|
+
- month option with p/f flag `calrom -m 5p` / `calrom -m 5f` as a shortcut to specify a month of the previous/following year
|
11
|
+
- option to print the whole current year `calrom -y`
|
12
|
+
- support arbitrary date range specified as two ISO dates
|
13
|
+
- input is validated, errors handled and reported
|
14
|
+
- cal-like option to print (only) the date of Easter
|
15
|
+
- cal-like debugging options `-d` and `-H`
|
16
|
+
- option `--[no-]color` to enable/disable ANSI colours (enabled by default)
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
|
20
|
+
- list view: contains weekday names; month names instead of month numbers
|
21
|
+
|
22
|
+
### Fixed
|
23
|
+
|
24
|
+
- unhandled edge-case in `Calrom::Month` when dealing with the end of a year
|
25
|
+
- liturgical colour violet
|
26
|
+
|
3
27
|
## [0.1.0] 2019-10-05
|
4
28
|
|
5
29
|
### Added
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# calrom
|
2
2
|
|
3
|
+
[](https://travis-ci.org/calendarium-romanum/calrom)
|
4
|
+
[](https://badge.fury.io/rb/calrom)
|
5
|
+
|
3
6
|
Command line utility providing access to the Roman Catholic
|
4
7
|
liturgical calendar (post-Vatican II).
|
5
8
|
|
@@ -9,11 +12,63 @@ Built on top of the [calendarium-romanum][caro] Ruby gem.
|
|
9
12
|
|
10
13
|
calrom is a Ruby gem:
|
11
14
|
|
12
|
-
|
15
|
+
`$ gem install calrom`
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
### Specifying date range
|
20
|
+
|
21
|
+
Print liturgical calendar for the current month (default):
|
22
|
+
|
23
|
+
`$ calrom`
|
24
|
+
|
25
|
+
... for a specified month of the current year:
|
26
|
+
|
27
|
+
`$ calrom -m 9`
|
28
|
+
|
29
|
+
... for a specified month of another year:
|
30
|
+
|
31
|
+
`$ calrom -m 1 2028` or `$ calrom 1 2028`
|
32
|
+
|
33
|
+
... for a whole year:
|
34
|
+
|
35
|
+
`$ calrom 2017`
|
36
|
+
|
37
|
+
... for the current year:
|
38
|
+
|
39
|
+
`$ calrom -y`
|
40
|
+
|
41
|
+
... for a specified date:
|
42
|
+
|
43
|
+
`$ calrom 2028-01-15`
|
44
|
+
|
45
|
+
... for an arbitrary date range:
|
46
|
+
|
47
|
+
`$ calrom 2028-01-15 2028-03-07`
|
48
|
+
|
49
|
+
### Data presentation settings
|
50
|
+
|
51
|
+
Print detailed listing:
|
52
|
+
|
53
|
+
`$ calrom -l`
|
54
|
+
|
55
|
+
Disable colours:
|
56
|
+
|
57
|
+
`$ calrom --no-color`
|
58
|
+
|
59
|
+
## Running tests
|
60
|
+
|
61
|
+
Clone the repository, `$ bundle install` to install dependencies, then:
|
62
|
+
|
63
|
+
`$ rake cucumber` - run specs describing the command line interface
|
64
|
+
|
65
|
+
`$ rake spec` - run specs describing internal implementation details
|
66
|
+
|
67
|
+
`$ rake` - run all groups of specs one after another
|
13
68
|
|
14
69
|
## Project roadmap
|
15
70
|
|
16
|
-
* [
|
71
|
+
* [x] detailed listing of a day/month/year/range of dates
|
17
72
|
* [ ] month/year overview - options and output mostly mimicking the
|
18
73
|
the BSD Unix [`cal`][cal] utility,
|
19
74
|
but with liturgical colours and celebration ranks
|
data/Rakefile
CHANGED
data/calrom.gemspec
CHANGED
@@ -22,8 +22,8 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_dependency 'calendarium-romanum', '~> 0.6.0'
|
24
24
|
spec.add_dependency 'colorize', '~> 0.8'
|
25
|
+
spec.add_dependency 'pattern-match', '~> 1.0'
|
25
26
|
|
26
|
-
spec.add_development_dependency 'bundler', '~> 1.13'
|
27
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
28
28
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
29
|
spec.add_development_dependency 'cucumber', '~> 1.3'
|
data/lib/calrom.rb
CHANGED
@@ -10,6 +10,11 @@ require 'calrom/cli'
|
|
10
10
|
require 'calrom/option_parser'
|
11
11
|
require 'calrom/config'
|
12
12
|
require 'calrom/date_range'
|
13
|
+
require 'calrom/exceptions'
|
13
14
|
require 'calrom/formatter/formatter'
|
14
15
|
require 'calrom/formatter/list'
|
16
|
+
require 'calrom/formatter/overview'
|
17
|
+
require 'calrom/formatter/easter'
|
18
|
+
require 'calrom/highlighter/no'
|
15
19
|
require 'calrom/highlighter/list'
|
20
|
+
require 'calrom/highlighter/overview'
|
data/lib/calrom/cli.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
module Calrom
|
2
2
|
class CLI
|
3
3
|
def self.call(argv)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
yielder.yield calendar[date]
|
10
|
-
end
|
4
|
+
begin
|
5
|
+
config = OptionParser.call argv
|
6
|
+
rescue ::OptionParser::InvalidOption, InputError => e
|
7
|
+
STDERR.puts e.message
|
8
|
+
exit 1
|
11
9
|
end
|
12
10
|
|
13
|
-
|
11
|
+
calendar = config.calendar
|
12
|
+
|
13
|
+
config.formatter.call calendar, config.date_range
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/calrom/config.rb
CHANGED
@@ -2,17 +2,31 @@ module Calrom
|
|
2
2
|
class Config
|
3
3
|
def initialize
|
4
4
|
self.today = Date.today
|
5
|
-
self.date_range =
|
5
|
+
self.date_range = Month.new(today.year, today.month)
|
6
6
|
end
|
7
7
|
|
8
|
-
attr_accessor :today, :date_range
|
8
|
+
attr_accessor :today, :date_range, :formatter, :colours
|
9
9
|
|
10
10
|
def calendar
|
11
11
|
CR::PerpetualCalendar.new(sanctorale: CR::Data::GENERAL_ROMAN_ENGLISH.load)
|
12
12
|
end
|
13
13
|
|
14
14
|
def formatter
|
15
|
-
|
15
|
+
if @formatter == :list || (@formatter.nil? && date_range.is_a?(Day))
|
16
|
+
Formatter::List.new highlighter(Highlighter::List), today
|
17
|
+
elsif @formatter == :easter
|
18
|
+
Formatter::Easter.new
|
19
|
+
else
|
20
|
+
Formatter::Overview.new highlighter(Highlighter::Overview), today
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def highlighter(colourful)
|
25
|
+
if self.colours == false
|
26
|
+
return Highlighter::No.new
|
27
|
+
end
|
28
|
+
|
29
|
+
colourful.new
|
16
30
|
end
|
17
31
|
end
|
18
32
|
end
|
data/lib/calrom/date_range.rb
CHANGED
@@ -1,5 +1,28 @@
|
|
1
1
|
module Calrom
|
2
2
|
class DateRange < Range
|
3
|
+
def each_month
|
4
|
+
return to_enum(:each_month) unless block_given?
|
5
|
+
|
6
|
+
if first.year == last.year && first.month == last.month
|
7
|
+
# a single month or it's part
|
8
|
+
yield self
|
9
|
+
return
|
10
|
+
end
|
11
|
+
|
12
|
+
(Month.new(first.year, first.month) .. Month.new(last.year, last.month))
|
13
|
+
.each_with_index do |m,i|
|
14
|
+
if i == 0 && first.day > 1
|
15
|
+
# first month, incomplete
|
16
|
+
end_of_month = first.next_month - first.day + 1
|
17
|
+
yield self.class.new(first, m.last)
|
18
|
+
elsif m.first.year == last.year && m.first.month == last.month && last != m.last
|
19
|
+
# last month, incomplete
|
20
|
+
yield self.class.new(m.first, last)
|
21
|
+
else
|
22
|
+
yield m
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
3
26
|
end
|
4
27
|
|
5
28
|
class Year < DateRange
|
@@ -10,15 +33,58 @@ module Calrom
|
|
10
33
|
def to_s
|
11
34
|
first.year.to_s
|
12
35
|
end
|
36
|
+
|
37
|
+
def each_month
|
38
|
+
return to_enum(:each_month) unless block_given?
|
39
|
+
|
40
|
+
1.upto(12) {|month| yield Month.new(first.year, month) }
|
41
|
+
end
|
13
42
|
end
|
14
43
|
|
15
44
|
class Month < DateRange
|
16
45
|
def initialize(year, month)
|
17
|
-
|
46
|
+
@year = year
|
47
|
+
@month = month
|
48
|
+
super Date.new(year, month, 1), next_month_beginning - 1
|
18
49
|
end
|
19
50
|
|
20
51
|
def to_s
|
21
|
-
|
52
|
+
first.strftime '%B %Y'
|
53
|
+
end
|
54
|
+
|
55
|
+
def each_month
|
56
|
+
return to_enum(:each_month) unless block_given?
|
57
|
+
|
58
|
+
yield self
|
59
|
+
end
|
60
|
+
|
61
|
+
def succ
|
62
|
+
n = next_month_beginning
|
63
|
+
self.class.new(n.year, n.month)
|
64
|
+
end
|
65
|
+
|
66
|
+
def <=>(other)
|
67
|
+
years_cmp = year <=> other.year
|
68
|
+
|
69
|
+
if years_cmp != 0
|
70
|
+
years_cmp
|
71
|
+
else
|
72
|
+
month <=> other.month
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
protected
|
77
|
+
|
78
|
+
attr_reader :year, :month
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def next_month_beginning
|
83
|
+
if @month == 12
|
84
|
+
Date.new(@year + 1, 1, 1)
|
85
|
+
else
|
86
|
+
Date.new(@year, @month + 1, 1)
|
87
|
+
end
|
22
88
|
end
|
23
89
|
end
|
24
90
|
|
@@ -30,5 +96,9 @@ module Calrom
|
|
30
96
|
def to_s
|
31
97
|
first.to_s
|
32
98
|
end
|
99
|
+
|
100
|
+
def each_month
|
101
|
+
yield self
|
102
|
+
end
|
33
103
|
end
|
34
104
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Calrom
|
2
|
+
module Formatter
|
3
|
+
# Prints (only) date of Easter for the specified year.
|
4
|
+
class Easter
|
5
|
+
def call(calendar, date_range)
|
6
|
+
unless date_range.is_a?(Year) || date_range.is_a?(Month)
|
7
|
+
raise 'unexpected date range, expected a year'
|
8
|
+
end
|
9
|
+
|
10
|
+
puts CalendariumRomanum::Temporale::Dates
|
11
|
+
.easter_sunday(date_range.first.year - 1)
|
12
|
+
.strftime('%D')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Calrom
|
2
2
|
module Formatter
|
3
3
|
class List < Formatter
|
4
|
-
def call(
|
4
|
+
def call(calendar, date_range)
|
5
5
|
print_months = date_range.first.month != date_range.last.month
|
6
6
|
|
7
7
|
puts date_range.to_s
|
@@ -9,12 +9,14 @@ module Calrom
|
|
9
9
|
|
10
10
|
current_month = nil
|
11
11
|
|
12
|
-
|
12
|
+
date_range.each do |date|
|
13
|
+
liturgical_day = calendar[date]
|
14
|
+
|
13
15
|
if print_months && liturgical_day.date.month != current_month
|
14
16
|
current_month = liturgical_day.date.month
|
15
17
|
|
16
18
|
puts
|
17
|
-
puts current_month
|
19
|
+
puts liturgical_day.date.strftime('%B') #current_month
|
18
20
|
puts
|
19
21
|
end
|
20
22
|
|
@@ -28,9 +30,10 @@ module Calrom
|
|
28
30
|
liturgical_day.celebrations.each_with_index do |celebration, i|
|
29
31
|
s =
|
30
32
|
if i > 0
|
31
|
-
' ' *
|
33
|
+
' ' * 6
|
32
34
|
else
|
33
|
-
liturgical_day.date.
|
35
|
+
liturgical_day.date.strftime('%a') +
|
36
|
+
liturgical_day.date.day.to_s.rjust(3)
|
34
37
|
end
|
35
38
|
s += ' '
|
36
39
|
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
module Calrom
|
5
|
+
module Formatter
|
6
|
+
class Overview < Formatter
|
7
|
+
def call(calendar, date_range, io = STDOUT)
|
8
|
+
colnum = (date_range.is_a?(Year) || date_range.each_month.to_a.size > 3) ? 3 : 1 # TODO: expose configuration
|
9
|
+
if date_range.is_a? Year
|
10
|
+
io.puts center_on(weekdays.size * colnum + 2 * (colnum - 1), date_range.to_s)
|
11
|
+
end
|
12
|
+
|
13
|
+
date_range.each_month.each_slice(colnum) do |months|
|
14
|
+
columns = months.collect do |month|
|
15
|
+
StringIO.new.tap do |io|
|
16
|
+
print_month io, calendar, month, date_range.is_a?(Year)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
print_columns columns, io
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def print_month(io, calendar, month, year_in_heading)
|
26
|
+
heading = month.first.strftime(year_in_heading ? '%B' : '%B %Y')
|
27
|
+
io.puts center_on weekdays.size, heading
|
28
|
+
|
29
|
+
io.puts weekdays
|
30
|
+
|
31
|
+
io.print ' ' * month.first.wday
|
32
|
+
month.each do |date|
|
33
|
+
liturgical_day = calendar[date]
|
34
|
+
|
35
|
+
celebration = liturgical_day.celebrations.first
|
36
|
+
|
37
|
+
datestr = date.day.to_s.rjust(2)
|
38
|
+
datestr = highlighter.colour(datestr, celebration.colour)
|
39
|
+
datestr = highlighter.rank(datestr, celebration.rank)
|
40
|
+
if date == today
|
41
|
+
datestr = highlighter.today datestr
|
42
|
+
end
|
43
|
+
io.print datestr
|
44
|
+
if date.wday == 6
|
45
|
+
io.puts
|
46
|
+
else
|
47
|
+
io.print ' '
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# localizable 2-character weekday shortcuts
|
53
|
+
def weekdays
|
54
|
+
@weekdays ||=
|
55
|
+
begin
|
56
|
+
sunday = Date.new 1987, 10, 25
|
57
|
+
sunday
|
58
|
+
.upto(sunday + 6)
|
59
|
+
.collect {|d| d.strftime('%a')[0..1] }
|
60
|
+
.join(' ')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# centers given string on a given line length
|
65
|
+
def center_on(line_length, content)
|
66
|
+
(' ' * (line_length / 2 - content.size / 2)) +
|
67
|
+
content
|
68
|
+
end
|
69
|
+
|
70
|
+
def print_columns(columns, io)
|
71
|
+
line_enumerators = columns.collect {|c| c.string.each_line }
|
72
|
+
not_yet_exhausted = Set.new line_enumerators
|
73
|
+
column_width = weekdays.size
|
74
|
+
|
75
|
+
loop do
|
76
|
+
break if not_yet_exhausted.empty?
|
77
|
+
|
78
|
+
line_enumerators.each do |l|
|
79
|
+
begin
|
80
|
+
line = l.next.chop
|
81
|
+
io.print line
|
82
|
+
io.print ' ' * (column_width - colour_aware_size(line))
|
83
|
+
rescue StopIteration
|
84
|
+
io.print ' ' * column_width
|
85
|
+
not_yet_exhausted.delete l
|
86
|
+
end
|
87
|
+
io.print ' '
|
88
|
+
end
|
89
|
+
io.puts
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# String length ignoring colour codes
|
94
|
+
def colour_aware_size(str)
|
95
|
+
ColorizedString.new(str).uncolorize.size
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -1,8 +1,13 @@
|
|
1
1
|
module Calrom
|
2
2
|
module Highlighter
|
3
3
|
class List
|
4
|
+
COLOUR_OVERRIDE = {
|
5
|
+
# 'colorize' does not know colour :violet
|
6
|
+
CR::Colours::VIOLET => :magenta,
|
7
|
+
}
|
8
|
+
|
4
9
|
def colour(text, colour)
|
5
|
-
ColorizedString.new(text).colorize(colour.symbol)
|
10
|
+
ColorizedString.new(text).colorize(COLOUR_OVERRIDE[colour] || colour.symbol)
|
6
11
|
end
|
7
12
|
|
8
13
|
def rank(text, rank)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Calrom
|
2
|
+
module Highlighter
|
3
|
+
class Overview < List
|
4
|
+
def rank(text, rank)
|
5
|
+
if rank.solemnity?
|
6
|
+
ColorizedString.new(text).colorize(mode: :bold)
|
7
|
+
elsif rank.feast?
|
8
|
+
ColorizedString.new(text).colorize(mode: :underline)
|
9
|
+
else
|
10
|
+
text
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/calrom/option_parser.rb
CHANGED
@@ -1,51 +1,167 @@
|
|
1
1
|
require 'optparse'
|
2
|
+
require 'pattern-match'
|
2
3
|
|
3
4
|
module Calrom
|
4
5
|
# Parses command line options, produces Config.
|
5
6
|
class OptionParser
|
7
|
+
using PatternMatch
|
8
|
+
|
6
9
|
def self.call(argv)
|
10
|
+
self.new.call(argv)
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(argv)
|
7
14
|
config = Config.new
|
8
15
|
|
9
16
|
today = config.today
|
10
17
|
year = today.year
|
11
18
|
month = today.month
|
12
19
|
day = nil
|
20
|
+
another_day = nil
|
13
21
|
|
14
22
|
range_type = nil
|
15
23
|
|
16
24
|
opt_parser = ::OptionParser.new do |opts|
|
17
|
-
|
18
|
-
|
25
|
+
opts.on('-l', '--list', 'list mode') do
|
26
|
+
config.formatter = :list
|
27
|
+
end
|
28
|
+
|
29
|
+
# cal
|
30
|
+
opts.on('-e', '--easter', 'display date of Easter') do
|
31
|
+
config.formatter = :easter
|
32
|
+
end
|
19
33
|
|
20
|
-
|
34
|
+
# cal
|
35
|
+
opts.on('-m MONTH', '--month=MONTH', 'display the specified month. \'f\' or \'p\' can be appended to display the same month of the following or previous year respectively') do |value|
|
21
36
|
range_type = :month
|
22
|
-
|
37
|
+
if value =~ /^(\d+)([pf])$/
|
38
|
+
month = $1
|
39
|
+
year = validate_year(year) + ($2 == 'f' ? 1 : -1)
|
40
|
+
else
|
41
|
+
month = value
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# cal
|
46
|
+
opts.on('-y', '--year', 'display specified (or current) year') do |value|
|
47
|
+
range_type = :year
|
48
|
+
end
|
49
|
+
|
50
|
+
# cal
|
51
|
+
opts.on('-d YM', '--current-month=YM', 'use given month (YYYY-MM) as the current month (for debugging of date range selection)') do |value|
|
52
|
+
year, month = value.split '-'
|
53
|
+
end
|
54
|
+
|
55
|
+
# cal
|
56
|
+
opts.on('-H DATE', '--highlight-date=DATE', 'use given date as the current date (for debugging of highlighting') do |value|
|
57
|
+
config.today = validate_day value
|
58
|
+
end
|
59
|
+
|
60
|
+
opts.on(nil, '--[no-]color', 'enable/disable colours (enabled by default)') do |value|
|
61
|
+
config.colours = value
|
62
|
+
end
|
63
|
+
|
64
|
+
opts.on_tail(nil, '--version', 'display calrom version') do
|
65
|
+
puts 'calrom v' + Calrom::VERSION
|
66
|
+
exit
|
67
|
+
end
|
68
|
+
|
69
|
+
# Normally optparse defines this option by default, but once -H option is added,
|
70
|
+
# for some reason -h (if not defined explicitly) is treated as -H.
|
71
|
+
opts.on_tail('-h', '--help', 'display this help') do
|
72
|
+
puts opts
|
73
|
+
exit
|
23
74
|
end
|
24
75
|
end
|
25
76
|
|
26
77
|
arguments = opt_parser.parse argv
|
27
78
|
|
28
|
-
|
29
|
-
|
30
|
-
|
79
|
+
iso_date_regexp = /^(\d{4}-\d{2}-\d{2})$/
|
80
|
+
match(arguments) do
|
81
|
+
with(_[iso_date_regexp.(date)]) do
|
31
82
|
range_type = :day
|
32
|
-
day =
|
33
|
-
|
83
|
+
day = date
|
84
|
+
end
|
85
|
+
|
86
|
+
with(_[iso_date_regexp.(date), iso_date_regexp.(another_date)]) do
|
87
|
+
range_type = :free
|
88
|
+
day = date
|
89
|
+
another_day = another_date
|
90
|
+
end
|
91
|
+
|
92
|
+
with(_[y]) do
|
34
93
|
range_type ||= :year
|
35
|
-
year =
|
94
|
+
year = y
|
95
|
+
end
|
96
|
+
|
97
|
+
with(_[m, y]) do
|
98
|
+
range_type = :month
|
99
|
+
month, year = m, y
|
100
|
+
end
|
101
|
+
|
102
|
+
with([]) {}
|
103
|
+
|
104
|
+
with(_) do
|
105
|
+
raise InputError.new('too many arguments')
|
36
106
|
end
|
37
107
|
end
|
38
108
|
|
39
109
|
config.date_range =
|
40
|
-
|
110
|
+
build_date_range(
|
111
|
+
range_type,
|
112
|
+
validate_year(year),
|
113
|
+
validate_month(month),
|
114
|
+
day && validate_day(day),
|
115
|
+
another_day && validate_day(another_day)
|
116
|
+
)
|
117
|
+
|
118
|
+
config.freeze
|
119
|
+
end
|
120
|
+
|
121
|
+
protected
|
122
|
+
|
123
|
+
def validate_year(year)
|
124
|
+
unless year.is_a?(Integer) || year =~ /^\d+$/
|
125
|
+
raise InputError.new("not a valid year #{year}")
|
126
|
+
end
|
127
|
+
|
128
|
+
year.to_i
|
129
|
+
end
|
130
|
+
|
131
|
+
def validate_month(month)
|
132
|
+
unless month.is_a?(Integer) ||
|
133
|
+
(month =~ /^\d+$/ && (1..12).include?(month.to_i))
|
134
|
+
raise InputError.new("not a valid month #{month}")
|
135
|
+
end
|
136
|
+
|
137
|
+
month.to_i
|
138
|
+
end
|
139
|
+
|
140
|
+
def validate_day(day)
|
141
|
+
Date.parse(day)
|
142
|
+
rescue ArgumentError
|
143
|
+
raise InputError.new("not a valid date #{day}")
|
144
|
+
end
|
145
|
+
|
146
|
+
def build_date_range(range_type, year, month, day, another_day=nil)
|
147
|
+
range =
|
148
|
+
case range_type
|
149
|
+
when :year
|
41
150
|
Year.new(year)
|
42
|
-
|
43
|
-
Day.new(
|
151
|
+
when :day
|
152
|
+
Day.new(day)
|
153
|
+
when :free
|
154
|
+
DateRange.new(day, another_day)
|
44
155
|
else
|
45
156
|
Month.new(year, month)
|
46
157
|
end
|
47
158
|
|
48
|
-
|
159
|
+
beginning = CalendariumRomanum::Calendar::EFFECTIVE_FROM
|
160
|
+
if range.first < beginning
|
161
|
+
raise InputError.new("implemented calendar system in use only since #{beginning}")
|
162
|
+
end
|
163
|
+
|
164
|
+
range
|
49
165
|
end
|
50
166
|
end
|
51
167
|
end
|
data/lib/calrom/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: calrom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakub Pavlík
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: calendarium-romanum
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.8'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: pattern-match
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1.
|
48
|
-
type: :
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1.
|
54
|
+
version: '1.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,9 +132,14 @@ files:
|
|
132
132
|
- lib/calrom/cli.rb
|
133
133
|
- lib/calrom/config.rb
|
134
134
|
- lib/calrom/date_range.rb
|
135
|
+
- lib/calrom/exceptions.rb
|
136
|
+
- lib/calrom/formatter/easter.rb
|
135
137
|
- lib/calrom/formatter/formatter.rb
|
136
138
|
- lib/calrom/formatter/list.rb
|
139
|
+
- lib/calrom/formatter/overview.rb
|
137
140
|
- lib/calrom/highlighter/list.rb
|
141
|
+
- lib/calrom/highlighter/no.rb
|
142
|
+
- lib/calrom/highlighter/overview.rb
|
138
143
|
- lib/calrom/option_parser.rb
|
139
144
|
- lib/calrom/version.rb
|
140
145
|
homepage: https://github.com/calendarium-romanum/calrom
|
@@ -157,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
162
|
version: '0'
|
158
163
|
requirements: []
|
159
164
|
rubyforge_project:
|
160
|
-
rubygems_version: 2.
|
165
|
+
rubygems_version: 2.7.6
|
161
166
|
signing_key:
|
162
167
|
specification_version: 4
|
163
168
|
summary: Command line utility providing access to the Roman Catholic liturgical calendar
|