printable_calendar 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b092f4e678d520d0d35cccf5431782d6d6d9aefd
4
- data.tar.gz: 85c3d3ebe5c194bfde45383a35bbe75d77eeb4f8
3
+ metadata.gz: 8e8fb99c08f3caffd178871c00f9babb4b1d2acb
4
+ data.tar.gz: cffef9e42bc08938773cac99d5e09f5305e17453
5
5
  SHA512:
6
- metadata.gz: 8256ad2d5af74eeeb1d8249337ede3027a462d970013dc2d2ccfba44698fa767aaef1c7d71d853e3fc0edca8a4108257ca2e2d9d3a30073e0564458ddbfe23c7
7
- data.tar.gz: 381e6ac7180d3d47f54bcedb69eaf4de23a4e8bf397c18b5a23822bcd9cb4665a3dd9a6fa081271b22765c1cfd33d97347743ae8e22b9932f22505d68b89967c
6
+ metadata.gz: f0567d2b04fa5bd6dec284b4119862cd70d0080b4f38ae734f1a2ab88dbee64178668f75c244be9dddc8b9eaac5aae5131574826dabf7ab8251a0329dda7ad79
7
+ data.tar.gz: 1d3f9cb69a71041cb2e0de4ead581051b153c6ea516afda96cb856d7175713bcb2d1ca944b07968b99925aba16ca4ef5b72a2b785bcecb25215a10edd2aec3b7
data/README.md CHANGED
@@ -25,16 +25,16 @@ There are a few other options. They're available in both the JSON file and as co
25
25
 
26
26
  ```
27
27
  usage: printable_calendar [options]
28
- -g, --generate generate a token
29
- -h, --help print help
30
- -v, --version print version info
31
- -c, --config use a JSON config file
28
+ -g, --generate Generate a token
29
+ -h, --help Print help
30
+ -v, --version Print version info
31
+ -c, --config Use a JSON config file
32
32
  --client-id Google client id
33
33
  --client-secret Google client secret
34
34
  --refresh-token Google refresh token
35
- --period time period to use
36
- --title title for this calendar
37
- --starting-from date to anchor on. Defaults to today. Format as YYYY-MM-DD
35
+ -p, --period Time period to use. Accepts workweek, american_week, intl_week, month, day
36
+ --title Title for this calendar
37
+ --starting-from Date to anchor on. Defaults to today. Format as YYYY-MM-DD
38
38
  --calendar-ids Google calendar IDs
39
39
  ```
40
40
 
@@ -14,16 +14,16 @@ def load_config_file(file)
14
14
  end
15
15
 
16
16
  opts = Slop.parse do |o|
17
- o.bool "-g", "--generate", "generate a token"
18
- o.bool "-h", "--help", "print help"
19
- o.bool "-v", "--version", "print version info"
20
- o.string "-c", "--config", "use a JSON config file"
17
+ o.bool "-g", "--generate", "Generate a token"
18
+ o.bool "-h", "--help", "Print help"
19
+ o.bool "-v", "--version", "Print version info"
20
+ o.string "-c", "--config", "Use a JSON config file"
21
21
  o.string "--client-id", "Google client id"
22
22
  o.string "--client-secret", "Google client secret"
23
23
  o.string "--refresh-token", "Google refresh token"
24
- o.string "--period", "time period to use"
25
- o.string "--title", "title for this calendar"
26
- o.string "--starting-from", "date to anchor on. Defaults to today. Format as YYYY-MM-DD"
24
+ o.string "-p", "--period", "Time period to use. Accepts #{PrintableCalendar::Range.supported_periods.join(", ")}"
25
+ o.string "--title", "Title for this calendar"
26
+ o.string "--starting-from", "Date to anchor on. Defaults to today. Format as YYYY-MM-DD"
27
27
  o.array "--calendar-ids", "Google calendar IDs"
28
28
  end
29
29
 
@@ -5,21 +5,28 @@ require "active_support/all"
5
5
  module PrintableCalendar
6
6
  class Range
7
7
 
8
+ def self.range_map
9
+ {
10
+ workweek: ->(t){[t.beginning_of_week(:monday), t.beginning_of_week(:monday) + 4]},
11
+ american_week: ->(t){[t.beginning_of_week(:sunday), t.end_of_week(:sunday)]},
12
+ intl_week: ->(t){[t.beginning_of_week(:monday), t.end_of_week(:sunday)]},
13
+ month: ->(t){[t.beginning_of_month, t.end_of_month]},
14
+ day: ->(t){[t, t]}
15
+ }
16
+ end
17
+
18
+ def self.supported_periods
19
+ range_map.keys.map{|k| k.to_s}
20
+ end
21
+
8
22
  def self.compute(period, startingFrom)
9
23
  t = startingFrom
10
- s, e = case period
11
- when "workweek"
12
- monday = t.beginning_of_week(:monday)
13
- [monday, monday + 4]
14
- when "americanweek"
15
- [t.beginning_of_week(:sunday), t.end_of_week(:sunday)]
16
- when "intlweek"
17
- [t.beginning_of_week(:monday), t.end_of_week(:sunday)]
18
- when "month"
19
- [t.beginning_of_month, t.end_of_month]
20
- else
21
- abort("Period must be one of 'workweek', 'americanweek', 'intlweek', or 'month'")
22
- end
24
+
25
+ mapper = range_map[period.to_sym]
26
+
27
+ abort "Unknown period #{period}. Use one of {#{supported_periods.join(", ")}}" unless mapper
28
+
29
+ s, e = mapper.(t)
23
30
  [s.beginning_of_day, e.end_of_day]
24
31
  end
25
32
  end
@@ -1,3 +1,3 @@
1
1
  module PrintableCalendar
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: printable_calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isaac Cambron