adzap-cronos 0.3.0 → 0.3.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.
Files changed (5) hide show
  1. data/CHANGELOG +3 -0
  2. data/Rakefile +2 -1
  3. data/lib/cronos.rb +18 -6
  4. data/spec/cronos_spec.rb +8 -0
  5. metadata +2 -2
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ == 0.3.1 2009-02-03
2
+ - added ranges to #days
3
+
1
4
  == 0.3.0 2009-01-27
2
5
  - better range handling for #on and #of including support for end excluded ranges
3
6
  - aliased #of with #in
data/Rakefile CHANGED
@@ -3,9 +3,10 @@ require 'rake/gempackagetask'
3
3
  require 'rubygems/specification'
4
4
  require 'date'
5
5
  require 'spec/rake/spectask'
6
+ require 'lib/cronos'
6
7
 
7
8
  GEM = "cronos"
8
- GEM_VERSION = "0.2.2"
9
+ GEM_VERSION = Cronos::VERSION
9
10
  AUTHOR = "Adam Meehan"
10
11
  EMAIL = "adam.meehan@gmail.com"
11
12
  HOMEPAGE = "http://github.com/adzap/cronos"
data/lib/cronos.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module Cronos
2
2
 
3
+ VERSION = '0.3.1'
4
+
3
5
  class Interval
4
6
  attr_accessor :min, :hour, :day, :month, :dow
5
7
 
@@ -55,12 +57,12 @@ module Cronos
55
57
  # on(13)
56
58
  # on('13th')
57
59
  # on(13..17)
60
+ # on(13...18)
58
61
  # on_the('13th')
59
62
  #
60
63
  def on(*args)
61
64
  if args.first.is_a?(Range)
62
- list = Array(args.first)
63
- @day = "#{list.first}-#{list.last}"
65
+ @day = format_range(args.first)
64
66
  else
65
67
  list = args.collect {|day| day.to_s.to_i }
66
68
  @day = list.join(',')
@@ -73,13 +75,19 @@ module Cronos
73
75
  # days(:monday)
74
76
  # days('Monday')
75
77
  # days(:mon)
78
+ # days(1..3)
79
+ # days(1...4)
76
80
  # on_day(:monday)
77
81
  # days(:mon, :tues)
78
82
  # on_days(:mon, :tues)
79
83
  #
80
84
  def days(*args)
81
- list = args.map {|day| DAYS.index(day.to_s.downcase[0..2].to_sym) }
82
- @dow = list.join(',')
85
+ if args.first.is_a?(Range)
86
+ @dow = format_range(args.first)
87
+ else
88
+ list = args.map {|day| DAYS.index(day.to_s.downcase[0..2].to_sym) }
89
+ @dow = list.join(',')
90
+ end
83
91
  self
84
92
  end
85
93
  alias on_days days
@@ -97,8 +105,7 @@ module Cronos
97
105
  #
98
106
  def of(*args)
99
107
  if args.first.is_a?(Range)
100
- list = Array(args.first)
101
- @month = "#{list.first}-#{list.last}"
108
+ @month = format_range(args.first)
102
109
  else
103
110
  list = args.map {|month| MONTHS.index(month.to_s.downcase[0..2].to_sym) + 1 unless month.is_a?(Fixnum) }
104
111
  @month = list.join(',')
@@ -197,6 +204,11 @@ module Cronos
197
204
  return hour, min, meridian
198
205
  end
199
206
 
207
+ def format_range(range)
208
+ list = Array(range).sort
209
+ "#{list.first}-#{list.last}"
210
+ end
211
+
200
212
  class RepeatInterval
201
213
 
202
214
  def initialize(multiple, interval)
data/spec/cronos_spec.rb CHANGED
@@ -128,6 +128,14 @@ describe Cronos::Interval do
128
128
  it "should output interval with day numbers from array of string day names" do
129
129
  interval.days('Monday', 'Wednesday', 'Friday').to_s.should == '* * * * 1,3,5'
130
130
  end
131
+
132
+ it "should output interval from integer inclusive range as dashed dow range " do
133
+ interval.days(1..3).to_s.should == '* * * * 1-3'
134
+ end
135
+
136
+ it "should output interval from integer exclusive range as dashed dow range " do
137
+ interval.days(1...4).to_s.should == '* * * * 1-3'
138
+ end
131
139
  end
132
140
 
133
141
  describe "hourly method" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adzap-cronos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Meehan
@@ -9,7 +9,7 @@ autorequire: cronos
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-17 00:00:00 -08:00
12
+ date: 2009-02-03 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15