midnight 0.0.1.pre → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3d56134d1c94d57b2f7b0f429e0cdb7cc5d08ace
4
- data.tar.gz: 9d5012f615745c6561d1d12c51af058ca613feb5
2
+ SHA256:
3
+ metadata.gz: 4674742cf82219099a8f3c15b08532cacd3c9f0df3823b4a4d9575a19b2b379e
4
+ data.tar.gz: d14c1b0e5a1b89770955e7ed72bda8d014f9715a145c9d465fb94ab8f0d27820
5
5
  SHA512:
6
- metadata.gz: ca450ea161e1ec9a365debbb9e22fb006c2df611c03d9039657b9095a522092db810fa1550437fa0b8e4e9d1b884e6d44fd9297523b9115a24d30425486ef0d9
7
- data.tar.gz: b0e3af7eea74b3bc7d8e96b134e26c1a45a12574729b4dd99d08c1c29ab5ed17e26a9b8f4c2d33202c06f4bcbf256b053cf99702bd4c5d20c34c4f1f4e260076
6
+ metadata.gz: a409610413d05d537dafac3ef4c655b69d7b7417f3faa38e6aed5e116306f1958f2faeaf9ced763dcf4fbdab0ad1e547988640acf170cc02b24473566451b3b3
7
+ data.tar.gz: 74a73ff5f702c6146c17430ed0f836bbb162536edd9be67de001e693b9caf41307c4497735ceb29f865640e35e54ef8e4c63705790ac8cc4ced2b15b1811ea6c
@@ -1,3 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.0
3
+ - 2.6.5
data/README.md CHANGED
@@ -2,11 +2,13 @@
2
2
 
3
3
  A library to parse natural language date/time into a cron expression.
4
4
 
5
+ [![Build Status](https://travis-ci.org/bluefuton/midnight.svg?branch=master)](https://travis-ci.org/bluefuton/midnight)
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
8
10
 
9
- gem 'midnight'
11
+ gem 'midnight', ">= 1.0.0"
10
12
 
11
13
  And then execute:
12
14
 
@@ -21,10 +23,22 @@ Or install it yourself as:
21
23
  <pre>Midnight.parse('every 5 minutes').to_s
22
24
  => "*/5 * * * *"</pre>
23
25
 
26
+ ### Supported phrases
27
+
28
+ A full list of supported natural language phrases can be found in <a href="https://github.com/bluefuton/midnight/blob/master/test/test_parsing.rb">test_parsing.rb</a>.
29
+
30
+ In the future there'll be support for more complex repetitions - a wishlist can be found in <a href="https://github.com/bluefuton/midnight/blob/master/todo.txt">todo.txt</a>.
31
+
32
+ ## Credits
33
+
34
+ My tokeniser code is based on the excellent <a href="https://github.com/yb66/tickle">Tickle</a> gem, which in turn relies on <a href="https://github.com/mojombo/chronic">Chronic</a> for date parsing.
35
+
36
+ Author: Chris Rosser <chris@bluefuton.com>
37
+
24
38
  ## Contributing
25
39
 
26
40
  1. Fork it ( http://github.com/bluefuton/midnight/fork )
27
41
  2. Create your feature branch (`git checkout -b my-new-feature`)
28
42
  3. Commit your changes (`git commit -am 'Add some feature'`)
29
43
  4. Push to the branch (`git push origin my-new-feature`)
30
- 5. Create new Pull Request
44
+ 5. Create new pull request
@@ -1,4 +1,4 @@
1
- require_relative "../numerizer/numerizer.rb"
1
+ require 'numerizer'
2
2
 
3
3
  module Midnight
4
4
  class << self
@@ -76,7 +76,8 @@ class Midnight::Repeater < Chronic::Tag #:nodoc:
76
76
  /^th(urs|ers)day?s?$/ => :thursday,
77
77
  /^thu$/ => :thursday,
78
78
  /^fr[iy](day)?s?$/ => :friday,
79
- /^sat(t?[ue]rday)?s?$/ => :saturday
79
+ /^sat(t?[ue]rday)?s?$/ => :saturday,
80
+ /^weekdays?$/ => :weekday,
80
81
  }
81
82
 
82
83
  day_sequence = {
@@ -86,7 +87,8 @@ class Midnight::Repeater < Chronic::Tag #:nodoc:
86
87
  :wednesday => 3,
87
88
  :thursday => 4,
88
89
  :friday => 5,
89
- :saturday => 6
90
+ :saturday => 6,
91
+ :weekday => '1-5',
90
92
  }
91
93
 
92
94
  scanner.each do |scanner_item, day|
@@ -1,3 +1,3 @@
1
1
  module Midnight
2
- VERSION = '0.0.1.pre'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -18,7 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.5"
21
+ spec.add_development_dependency "bundler", ">= 1.0.0"
22
22
  spec.add_development_dependency "rake", '~> 0'
23
+ spec.add_development_dependency 'test-unit'
23
24
  spec.add_dependency 'chronic', '=0.10.2'
25
+ spec.add_dependency 'numerizer', '~> 0.1.1'
24
26
  end
@@ -41,7 +41,8 @@ class TestParsing < Test::Unit::TestCase
41
41
  'midnight on tuesdays' => '0 0 * * 2',
42
42
  'every 5 minutes on Tuesdays' => '*/5 * * * 2',
43
43
  'every other day' => nil, # other is currently unsupported
44
- 'noon' => '0 12 * * *'
44
+ 'noon' => '0 12 * * *',
45
+ 'midnight on weekdays' => '0 0 * * 1-5'
45
46
  }
46
47
 
47
48
  expected_results.each do |search,cron_string|
data/todo.txt CHANGED
@@ -14,7 +14,6 @@ the 10th of the month
14
14
  the tenth of the month
15
15
  the 3rd Sunday of the month
16
16
  out of bounds values e.g. 4:61pm
17
- midday - 'noon' works, so Chronic could be patched
18
17
  every 5 minutes on fridays
19
18
  multiple days "every tuesday, wednesday and friday at 5pm"
20
19
  multiple hours or minutes
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: midnight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bluefuton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-14 00:00:00.000000000 Z
11
+ date: 2019-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.5'
19
+ version: 1.0.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.5'
26
+ version: 1.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: chronic
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - '='
53
67
  - !ruby/object:Gem::Version
54
68
  version: 0.10.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: numerizer
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.1
55
83
  description: ''
56
84
  email:
57
85
  - chris@bluefuton.com
@@ -66,7 +94,6 @@ files:
66
94
  - LICENSE
67
95
  - LICENSE.txt
68
96
  - README.md
69
- - README.textile
70
97
  - Rakefile
71
98
  - lib/midnight.rb
72
99
  - lib/midnight/converter.rb
@@ -75,7 +102,6 @@ files:
75
102
  - lib/midnight/midnight.rb
76
103
  - lib/midnight/repeater.rb
77
104
  - lib/midnight/version.rb
78
- - lib/numerizer/numerizer.rb
79
105
  - midnight.gemspec
80
106
  - test/helper.rb
81
107
  - test/test_cron_expression.rb
@@ -96,12 +122,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
122
  version: '0'
97
123
  required_rubygems_version: !ruby/object:Gem::Requirement
98
124
  requirements:
99
- - - ">"
125
+ - - ">="
100
126
  - !ruby/object:Gem::Version
101
- version: 1.3.1
127
+ version: '0'
102
128
  requirements: []
103
- rubyforge_project:
104
- rubygems_version: 2.2.2
129
+ rubygems_version: 3.0.3
105
130
  signing_key:
106
131
  specification_version: 4
107
132
  summary: Parse natural language date/time into a cron expression
@@ -109,4 +134,3 @@ test_files:
109
134
  - test/helper.rb
110
135
  - test/test_cron_expression.rb
111
136
  - test/test_parsing.rb
112
- has_rdoc:
@@ -1,20 +0,0 @@
1
- h1. midnight
2
-
3
- <img src="https://api.travis-ci.org/bluefuton/midnight.png" alt="Travis build status" />
4
-
5
- A library to parse natural language date/time into a cron expression.
6
-
7
- <pre>Midnight.parse('every 5 minutes').to_s
8
- => "*/5 * * * *"</pre>
9
-
10
- h2. Supported phrases
11
-
12
- A full list of supported natural language phrases can be found in <a href="https://github.com/bluefuton/midnight/blob/develop/test/test_parsing.rb">test_parsing.rb</a>.
13
-
14
- In the future there'll be support for more complex repetitions - a wishlist can be found in <a href="https://github.com/bluefuton/midnight/blob/develop/todo.txt">todo.txt</a>.
15
-
16
- h2. Credits
17
-
18
- My tokeniser code is based on the excellent <a href="https://github.com/yb66/tickle">Tickle</a> gem, which in turn relies on <a href="https://github.com/mojombo/chronic">Chronic</a> for date parsing.
19
-
20
- Author: Chris Rosser <chris@bluefuton.com>
@@ -1,103 +0,0 @@
1
- require 'strscan'
2
-
3
- class Numerizer
4
-
5
- DIRECT_NUMS = [
6
- ['eleven', '11'],
7
- ['twelve', '12'],
8
- ['thirteen', '13'],
9
- ['fourteen', '14'],
10
- ['fifteen', '15'],
11
- ['sixteen', '16'],
12
- ['seventeen', '17'],
13
- ['eighteen', '18'],
14
- ['nineteen', '19'],
15
- ['ninteen', '19'], # Common mis-spelling
16
- ['zero', '0'],
17
- ['one', '1'],
18
- ['two', '2'],
19
- ['three', '3'],
20
- ['four(\W|$)', '4\1'], # The weird regex is so that it matches four but not fourty
21
- ['five', '5'],
22
- ['six(\W|$)', '6\1'],
23
- ['seven(\W|$)', '7\1'],
24
- ['eight(\W|$)', '8\1'],
25
- ['nine(\W|$)', '9\1'],
26
- ['ten', '10'],
27
- ['\ba[\b^$]', '1'] # doesn't make sense for an 'a' at the end to be a 1
28
- ]
29
-
30
- TEN_PREFIXES = [ ['twenty', 20],
31
- ['thirty', 30],
32
- ['fourty', 40],
33
- ['fifty', 50],
34
- ['sixty', 60],
35
- ['seventy', 70],
36
- ['eighty', 80],
37
- ['ninety', 90]
38
- ]
39
-
40
- BIG_PREFIXES = [ ['hundred', 100],
41
- ['thousand', 1000],
42
- ['million', 1_000_000],
43
- ['billion', 1_000_000_000],
44
- ['trillion', 1_000_000_000_000],
45
- ]
46
-
47
- class << self
48
- def numerize(string)
49
- string = string.dup
50
-
51
- # preprocess
52
- string.gsub!(/ +|([^\d])-([^d])/, '\1 \2') # will mutilate hyphenated-words but shouldn't matter for date extraction
53
- string.gsub!(/a half/, 'haAlf') # take the 'a' out so it doesn't turn into a 1, save the half for the end
54
-
55
- # easy/direct replacements
56
-
57
- DIRECT_NUMS.each do |dn|
58
- string.gsub!(/#{dn[0]}/i, dn[1])
59
- end
60
-
61
- # ten, twenty, etc.
62
-
63
- TEN_PREFIXES.each do |tp|
64
- string.gsub!(/(?:#{tp[0]})( *\d(?=[^\d]|$))*/i) { (tp[1] + $1.to_i).to_s }
65
- end
66
-
67
- # hundreds, thousands, millions, etc.
68
-
69
- BIG_PREFIXES.each do |bp|
70
- string.gsub!(/(\d*) *#{bp[0]}/i) { (bp[1] * $1.to_i).to_s}
71
- andition(string)
72
- #combine_numbers(string) # Should to be more efficient way to do this
73
- end
74
-
75
- # fractional addition
76
- # I'm not combining this with the previous block as using float addition complicates the strings
77
- # (with extraneous .0's and such )
78
- string.gsub!(/(\d+)(?: | and |-)*haAlf/i) { ($1.to_f + 0.5).to_s }
79
-
80
- string
81
- end
82
-
83
- private
84
- def andition(string)
85
- sc = StringScanner.new(string)
86
- while(sc.scan_until(/(\d+)( | and )(\d+)(?=[^\w]|$)/i))
87
- if sc[2] =~ /and/ || sc[1].size > sc[3].size
88
- string[(sc.pos - sc.matched_size)..(sc.pos-1)] = (sc[1].to_i + sc[3].to_i).to_s
89
- sc.reset
90
- end
91
- end
92
- end
93
-
94
- # def combine_numbers(string)
95
- # sc = StringScanner.new(string)
96
- # while(sc.scan_until(/(\d+)(?: | and |-)(\d+)(?=[^\w]|$)/i))
97
- # string[(sc.pos - sc.matched_size)..(sc.pos-1)] = (sc[1].to_i + sc[2].to_i).to_s
98
- # sc.reset
99
- # end
100
- # end
101
-
102
- end
103
- end