cronspeak 0.1.5 → 0.1.6

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: 0c3b387750c2f7e0acf7b24e5a9e16b08ca19339
4
- data.tar.gz: 091a8744419f7f40192697dbebf9ec4ea5d8701c
3
+ metadata.gz: b48ca04c5db37a5257d2ea8cc6f1ba312a87a4f6
4
+ data.tar.gz: 87b13a3016a874fb2fde426160aab10b1f1c7e33
5
5
  SHA512:
6
- metadata.gz: 18b08e0d2dfc10424f58c64206080600d9a409ca6782e358440efacb9dbd6fbf552cf94960808e24d199a8cf2724651a01cf191b289f6ffbbf180da321035252
7
- data.tar.gz: 8379cadd755eafb75c5c8f2e6fac883936ae17a28fc55c54136257b1bf06ab927c17cc1711c5276079145c557051f9bb38fb7af4b34e07e765199c7086582610
6
+ metadata.gz: f6d79fb18d64a2a53c8128cc8cf904b808548d0be2c196c0a97a3b9d85214b37132008c748221c6f3483eae2924c3735d6a318808b440e9cfab78c6a1dedbf12
7
+ data.tar.gz: b8388d7c30bd5d5d1578efcebbc7c24a530ef0b80d44ae09e521bb76ed1c619f99303d9bd8e69d7e13653bf7735ff3b8360ee50708ce2aaf1f020b2ba233f6c4
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/cronspeak.rb CHANGED
@@ -40,14 +40,15 @@ class CronSpeak
40
40
 
41
41
  def mins(m='*')
42
42
 
43
- r = if m == '*' then
44
- 'every minute of '
45
- elsif m[/^\*\//]
43
+ return 'every minute of ' if m == '*'
44
+
45
+ r = case m
46
+ when /^\*\//
46
47
  m = m[/^\*\/(\d+)/,1]
47
48
  "every %s minute of " % [m.to_i.ordinal]
48
- elsif m =~ /,/
49
+ when /,/
49
50
  "%s minutes of " % m.split(/,/).map {|x| x.to_i.ordinal }.join(' and ')
50
- elsif m =~ /\-/
51
+ when /\-/
51
52
  "the %s minutes of " % m.split('-',2)\
52
53
  .map {|x| x.to_i.ordinal }.join(' through ')
53
54
  else
@@ -59,43 +60,43 @@ class CronSpeak
59
60
 
60
61
  def hrs(h='*')
61
62
 
62
- r = if h == '*' then
63
- 'every hour'
64
- elsif h[/^\*\//]
63
+ return 'every hour' if h == '*'
64
+
65
+ @count += 2
66
+
67
+ return case h
68
+ when /^\*\//
65
69
  h = h[/^\*\/(\d+)/,1]
66
70
  " of every %s hour" % [h.to_i.ordinal]
67
- elsif h =~ /,/
68
- "%s" % h.split(/,/)\
71
+ when /,/
72
+ h.split(/,/)\
69
73
  .map {|x| Time.parse(x+':00').strftime("%l%P").lstrip }.join(' and ')
70
- elsif h =~ /,/
74
+ when /,/
71
75
  "%s of " % h.split(/,/).map {|x| x.to_i.ordinal }.join(' and ')
72
- elsif h =~ /\-/
73
- "%s" % h.split('-',2).map do |x|
74
- Time.parse(x+':00').strftime("%l%P").lstrip
75
- end.join(' through ')
76
+ when /\-/
77
+ h.split('-',2).map {|x| Time.parse(x+':00').strftime("%l%P").lstrip }\
78
+ .join(' through ')
76
79
  else
77
- "%s" % [Time.parse(h+':00').strftime("%l%P").lstrip]
80
+ [Time.parse(h+':00').strftime("%l%P").lstrip]
78
81
  end
79
82
 
80
- @count += 2
81
-
82
- return r
83
83
  end
84
84
 
85
85
  def days(d='*')
86
86
 
87
- r = if @count >= 8 then
88
- " %s in " % @dow
89
- elsif d == '*' then
87
+ return " %s in " % @dow if @count >= 8
88
+
89
+ return case d
90
+ when /^\*$/ then
90
91
  ' every day'
91
- elsif d[/^\*\//]
92
+ when/^\*\//
92
93
  d = d[/^\*\/(\d+)/,1]
93
94
  @count += 4
94
95
  " of every %s day" % [d.to_i.ordinal]
95
- elsif d =~ /,/
96
+ when /,/
96
97
  @count += 8
97
98
  "the %s of " % d.split(/,/).map {|x| x.to_i.ordinal }.join(' and ')
98
- elsif d =~ /\-/
99
+ when /\-/
99
100
  @count += 8
100
101
  " the %s " % d.split('-',2).map {|x| x.to_i.ordinal }.join(' through ')
101
102
  else
@@ -103,12 +104,12 @@ class CronSpeak
103
104
  " the %s" % [d.to_i.ordinal]
104
105
  end
105
106
 
106
- return r
107
107
  end
108
108
 
109
109
  def months(mon='*')
110
110
 
111
- r = if mon == '*' then
111
+ r = case mon
112
+ when /^\*$/
112
113
 
113
114
  if @count < 4 then
114
115
  ''
@@ -117,14 +118,14 @@ class CronSpeak
117
118
  s + 'every month'
118
119
  end
119
120
 
120
- elsif mon[/^\*\//]
121
+ when /^\*\//
121
122
  mon = mon[/^\*\/(\d+)/,1]
122
123
  @count += 16
123
124
  " of every %s month" % [mon.to_i.ordinal]
124
- elsif mon =~ /,/
125
+ when /,/
125
126
  " of %s" % mon.split(/,/)\
126
127
  .map {|x| Date::MONTHNAMES[x.to_i] }.join(' and ')
127
- elsif mon =~ /\-/
128
+ when /\-/
128
129
  " of %s" % mon.split('-',2).map {|x| Date::MONTHNAMES[x.to_i] }.join(' through ')
129
130
  else
130
131
  s = @count < 8 ? 'of ' : ''
@@ -136,10 +137,23 @@ class CronSpeak
136
137
  return r
137
138
  end
138
139
 
139
- def dow(raw_dow='*')
140
- return '' if raw_dow == '*'
141
- @count += 8
142
- @dow = Date::DAYNAMES[raw_dow.to_i] + 's'
140
+ def dow(raw_dow='*')
141
+
142
+ @dow = case raw_dow
143
+ when /^\*$/
144
+ ''
145
+ when /,/
146
+ @count += 8
147
+ raw_dow.split(/,/).map {|x| Date::DAYNAMES[x.to_i] + 's' }.join(' and ')
148
+ when /\-/
149
+ @count += 8
150
+ raw_dow.split('-',2).map {|x| Date::DAYNAMES[x.to_i] + 's' }\
151
+ .join(' through ')
152
+ else
153
+ @count += 8
154
+ Date::DAYNAMES[raw_dow.to_i] + 's'
155
+ end
156
+
143
157
  end
144
158
 
145
159
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cronspeak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file