chronic 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ pkg
2
+ *.rbc
3
+ rdoc
4
+ .yardoc
@@ -0,0 +1,3 @@
1
+ -m markdown
2
+ --main README.md
3
+ --title "Chronic - Natural language date/time parsing"
data/Rakefile CHANGED
@@ -1,44 +1,10 @@
1
1
  require 'date'
2
2
 
3
- #############################################################################
4
- #
5
- # Helper functions
6
- #
7
- #############################################################################
8
-
9
- def name
10
- @name ||= Dir['*.gemspec'].first.split('.').first
11
- end
12
-
13
3
  def version
14
- line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
15
- line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
16
- end
17
-
18
- def rubyforge_project
19
- name
20
- end
21
-
22
- def gemspec_file
23
- "#{name}.gemspec"
4
+ contents = File.read File.expand_path('../lib/chronic.rb', __FILE__)
5
+ contents[/VERSION = "([^"]+)"/, 1]
24
6
  end
25
7
 
26
- def gem_file
27
- "#{name}-#{version}.gem"
28
- end
29
-
30
- def replace_header(head, header_name)
31
- head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
32
- end
33
-
34
- #############################################################################
35
- #
36
- # Standard tasks
37
- #
38
- #############################################################################
39
-
40
- task :default => :test
41
-
42
8
  require 'rake/testtask'
43
9
  Rake::TestTask.new(:test) do |test|
44
10
  test.libs << 'lib' << 'test'
@@ -59,20 +25,7 @@ task :console do
59
25
  sh "irb -Ilib -rchronic"
60
26
  end
61
27
 
62
- #############################################################################
63
- #
64
- # Custom tasks (add your own tasks here)
65
- #
66
- #############################################################################
67
-
68
-
69
-
70
- #############################################################################
71
- #
72
- # Packaging tasks
73
- #
74
- #############################################################################
75
-
28
+ desc "Release Chronic version #{version}"
76
29
  task :release => :build do
77
30
  unless `git branch` =~ /^\* master$/
78
31
  puts "You must be on the master branch to release!"
@@ -82,51 +35,14 @@ task :release => :build do
82
35
  sh "git tag v#{version}"
83
36
  sh "git push origin master"
84
37
  sh "git push origin v#{version}"
85
- sh "gem push pkg/#{name}-#{version}.gem"
38
+ sh "gem push pkg/chronic-#{version}.gem"
86
39
  end
87
40
 
88
- task :build => :gemspec do
41
+ desc "Build a gem from the gemspec"
42
+ task :build do
89
43
  sh "mkdir -p pkg"
90
- sh "gem build #{gemspec_file}"
91
- sh "mv #{gem_file} pkg"
44
+ sh "gem build chronic.gemspec"
45
+ sh "mv chronic-#{version}.gem pkg"
92
46
  end
93
47
 
94
- task :gemspec => :validate do
95
- # read spec file and split out manifest section
96
- spec = File.read(gemspec_file)
97
- head, manifest, tail = spec.split(" # = MANIFEST =\n")
98
-
99
- # replace name version and date
100
- replace_header(head, :name)
101
- replace_header(head, :version)
102
-
103
- #comment this out if your rubyforge_project has a different name
104
- replace_header(head, :rubyforge_project)
105
-
106
- # determine file list from git ls-files
107
- files = `git ls-files`.
108
- split("\n").
109
- sort.
110
- reject { |file| file =~ /^\./ }.
111
- reject { |file| file =~ /^(rdoc|pkg)/ }.
112
- map { |file| " #{file}" }.
113
- join("\n")
114
-
115
- # piece file back together and write
116
- manifest = " s.files = %w[\n#{files}\n ]\n"
117
- spec = [head, manifest, tail].join(" # = MANIFEST =\n")
118
- File.open(gemspec_file, 'w') { |io| io.write(spec) }
119
- puts "Updated #{gemspec_file}"
120
- end
121
-
122
- task :validate do
123
- libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
124
- unless libfiles.empty?
125
- puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
126
- exit!
127
- end
128
- unless Dir['VERSION*'].empty?
129
- puts "A `VERSION` file at root level violates Gem best practices."
130
- exit!
131
- end
132
- end
48
+ task :default => :test
@@ -1,83 +1,17 @@
1
+ $:.unshift File.expand_path('../lib', __FILE__)
2
+ require 'chronic'
3
+
1
4
  Gem::Specification.new do |s|
2
- s.name = 'chronic'
3
- s.version = '0.4.2'
5
+ s.name = 'chronic'
6
+ s.version = Chronic::VERSION
4
7
  s.rubyforge_project = 'chronic'
5
-
6
- s.summary = "Natural language date/time parsing."
7
- s.description = "Chronic is a natural language date/time parser written in pure Ruby."
8
-
9
- s.authors = ["Tom Preston-Werner", "Lee Jarvis"]
8
+ s.summary = 'Natural language date/time parsing.'
9
+ s.description = 'Chronic is a natural language date/time parser written in pure Ruby.'
10
+ s.authors = ['Tom Preston-Werner', 'Lee Jarvis']
10
11
  s.email = ['tom@mojombo.com', 'lee@jarvis.co']
11
12
  s.homepage = 'http://github.com/mojombo/chronic'
12
-
13
- s.rdoc_options = ["--charset=UTF-8"]
13
+ s.rdoc_options = ['--charset=UTF-8']
14
14
  s.extra_rdoc_files = %w[README.md HISTORY.md LICENSE]
15
-
16
- # = MANIFEST =
17
- s.files = %w[
18
- HISTORY.md
19
- LICENSE
20
- Manifest.txt
21
- README.md
22
- Rakefile
23
- benchmark/benchmark.rb
24
- chronic.gemspec
25
- lib/chronic.rb
26
- lib/chronic/chronic.rb
27
- lib/chronic/grabber.rb
28
- lib/chronic/handlers.rb
29
- lib/chronic/mini_date.rb
30
- lib/chronic/numerizer.rb
31
- lib/chronic/ordinal.rb
32
- lib/chronic/pointer.rb
33
- lib/chronic/repeater.rb
34
- lib/chronic/repeaters/repeater_day.rb
35
- lib/chronic/repeaters/repeater_day_name.rb
36
- lib/chronic/repeaters/repeater_day_portion.rb
37
- lib/chronic/repeaters/repeater_fortnight.rb
38
- lib/chronic/repeaters/repeater_hour.rb
39
- lib/chronic/repeaters/repeater_minute.rb
40
- lib/chronic/repeaters/repeater_month.rb
41
- lib/chronic/repeaters/repeater_month_name.rb
42
- lib/chronic/repeaters/repeater_season.rb
43
- lib/chronic/repeaters/repeater_season_name.rb
44
- lib/chronic/repeaters/repeater_second.rb
45
- lib/chronic/repeaters/repeater_time.rb
46
- lib/chronic/repeaters/repeater_week.rb
47
- lib/chronic/repeaters/repeater_weekday.rb
48
- lib/chronic/repeaters/repeater_weekend.rb
49
- lib/chronic/repeaters/repeater_year.rb
50
- lib/chronic/scalar.rb
51
- lib/chronic/separator.rb
52
- lib/chronic/span.rb
53
- lib/chronic/tag.rb
54
- lib/chronic/time_zone.rb
55
- lib/chronic/token.rb
56
- test/helper.rb
57
- test/test_Chronic.rb
58
- test/test_DaylightSavings.rb
59
- test/test_Handler.rb
60
- test/test_MiniDate.rb
61
- test/test_Numerizer.rb
62
- test/test_RepeaterDayName.rb
63
- test/test_RepeaterFortnight.rb
64
- test/test_RepeaterHour.rb
65
- test/test_RepeaterMinute.rb
66
- test/test_RepeaterMonth.rb
67
- test/test_RepeaterMonthName.rb
68
- test/test_RepeaterTime.rb
69
- test/test_RepeaterWeek.rb
70
- test/test_RepeaterWeekday.rb
71
- test/test_RepeaterWeekend.rb
72
- test/test_RepeaterYear.rb
73
- test/test_Span.rb
74
- test/test_Time.rb
75
- test/test_Token.rb
76
- test/test_parsing.rb
77
- ]
78
- # = MANIFEST =
79
-
80
- ## Test files will be grabbed from the file list. Make sure the path glob
81
- ## matches what you actually use.
82
- s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
83
- end
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- test`.split("\n")
17
+ end
@@ -28,7 +28,7 @@ require 'date'
28
28
  #
29
29
  # @author Tom Preston-Werner, Lee Jarvis
30
30
  module Chronic
31
- VERSION = "0.4.2"
31
+ VERSION = "0.4.3"
32
32
 
33
33
  class << self
34
34
 
@@ -108,7 +108,7 @@ module Chronic
108
108
  #
109
109
  # @param [String] text The string to normalize
110
110
  # @return [String] A new string ready for Chronic to parse
111
- def pre_normalize(text) #:nodoc:
111
+ def pre_normalize(text)
112
112
  text = text.to_s.downcase
113
113
  text.gsub!(/['"\.,]/, '')
114
114
  text.gsub!(/\bsecond (of|day|month|hour|minute|second)\b/, '2nd \1')
@@ -235,7 +235,7 @@ module Chronic
235
235
  tokens.select { |token| token.tagged? }
236
236
  end
237
237
 
238
- def tokens_to_span(tokens, options) #:nodoc:
238
+ def tokens_to_span(tokens, options)
239
239
  definitions = definitions(options)
240
240
 
241
241
  (definitions[:date] + definitions[:endian]).each do |handler|
@@ -8,8 +8,8 @@ module Chronic
8
8
  # @param [Hash] options Options specified in {Chronic.parse}
9
9
  # @return [Array] list of tokens
10
10
  def self.scan(tokens, options)
11
- tokens.each_index do |i|
12
- if t = scan_for_all(tokens[i]) then tokens[i].tag(t); next end
11
+ tokens.each do |token|
12
+ if t = scan_for_all(token) then token.tag(t); next end
13
13
  end
14
14
  end
15
15
 
@@ -8,9 +8,9 @@ module Chronic
8
8
  # @param [Hash] options Options specified in {Chronic.parse}
9
9
  # @return [Array] list of tokens
10
10
  def self.scan(tokens, options)
11
- tokens.each_index do |i|
12
- if t = scan_for_ordinals(tokens[i]) then tokens[i].tag(t) end
13
- if t = scan_for_days(tokens[i]) then tokens[i].tag(t) end
11
+ tokens.each do |token|
12
+ if t = scan_for_ordinals(token) then token.tag(t) end
13
+ if t = scan_for_days(token) then token.tag(t) end
14
14
  end
15
15
  end
16
16
 
@@ -8,8 +8,8 @@ module Chronic
8
8
  # @param [Hash] options Options specified in {Chronic.parse}
9
9
  # @return [Array] list of tokens
10
10
  def self.scan(tokens, options)
11
- tokens.each_index do |i|
12
- if t = scan_for_all(tokens[i]) then tokens[i].tag(t) end
11
+ tokens.each do |token|
12
+ if t = scan_for_all(token) then token.tag(t) end
13
13
  end
14
14
  end
15
15
 
@@ -8,13 +8,13 @@ module Chronic
8
8
  # @param [Hash] options Options specified in {Chronic.parse}
9
9
  # @return [Array] list of tokens
10
10
  def self.scan(tokens, options)
11
- tokens.each_index do |i|
12
- if t = scan_for_season_names(tokens[i]) then tokens[i].tag(t); next end
13
- if t = scan_for_month_names(tokens[i]) then tokens[i].tag(t); next end
14
- if t = scan_for_day_names(tokens[i]) then tokens[i].tag(t); next end
15
- if t = scan_for_day_portions(tokens[i]) then tokens[i].tag(t); next end
16
- if t = scan_for_times(tokens[i]) then tokens[i].tag(t); next end
17
- if t = scan_for_units(tokens[i]) then tokens[i].tag(t); next end
11
+ tokens.each do |token|
12
+ if t = scan_for_season_names(token) then token.tag(t); next end
13
+ if t = scan_for_month_names(token) then token.tag(t); next end
14
+ if t = scan_for_day_names(token) then token.tag(t); next end
15
+ if t = scan_for_day_portions(token) then token.tag(t); next end
16
+ if t = scan_for_times(token) then token.tag(t); next end
17
+ if t = scan_for_units(token) then token.tag(t); next end
18
18
  end
19
19
  end
20
20
 
@@ -37,7 +37,7 @@ module Chronic
37
37
  hours == 12 ? Tick.new(0 * 60 * 60, true) : Tick.new(hours * 60 * 60, true)
38
38
  when 3
39
39
  hours = t[0..0].to_i
40
- ambiguous = hours > 1
40
+ ambiguous = hours > 0
41
41
  Tick.new((hours * 60 * 60) + (t[1..2].to_i * 60), ambiguous)
42
42
  when 4
43
43
  ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
@@ -8,12 +8,12 @@ module Chronic
8
8
  # @param [Hash] options Options specified in {Chronic.parse}
9
9
  # @return [Array] list of tokens
10
10
  def self.scan(tokens, options)
11
- tokens.each_index do |i|
12
- if t = scan_for_commas(tokens[i]) then tokens[i].tag(t); next end
13
- if t = scan_for_slash_or_dash(tokens[i]) then tokens[i].tag(t); next end
14
- if t = scan_for_at(tokens[i]) then tokens[i].tag(t); next end
15
- if t = scan_for_in(tokens[i]) then tokens[i].tag(t); next end
16
- if t = scan_for_on(tokens[i]) then tokens[i].tag(t); next end
11
+ tokens.each do |token|
12
+ if t = scan_for_commas(token) then token.tag(t); next end
13
+ if t = scan_for_slash_or_dash(token) then token.tag(t); next end
14
+ if t = scan_for_at(token) then token.tag(t); next end
15
+ if t = scan_for_in(token) then token.tag(t); next end
16
+ if t = scan_for_on(token) then token.tag(t); next end
17
17
  end
18
18
  end
19
19
 
@@ -1,13 +1,17 @@
1
1
  module Chronic
2
2
  # Tokens are tagged with subclassed instances of this class when
3
3
  # they match specific criteria
4
- class Tag #:nodoc:
4
+ class Tag
5
+
6
+ # @return [Symbol]
5
7
  attr_accessor :type
6
8
 
9
+ # @param [Symbol] type
7
10
  def initialize(type)
8
11
  @type = type
9
12
  end
10
13
 
14
+ # @param [Time] s Set the start timestamp for this Tag
11
15
  def start=(s)
12
16
  @now = s
13
17
  end
@@ -15,6 +19,11 @@ module Chronic
15
19
  class << self
16
20
  private
17
21
 
22
+ # @param [Token] token
23
+ # @param [Class] klass The class instance to create
24
+ # @param [Regexp, Hash] items
25
+ # @return [Object, nil] either a new instance of `klass` or `nil` if
26
+ # no match is found
18
27
  def scan_for(token, klass, items={})
19
28
  case items
20
29
  when Regexp
@@ -8,8 +8,8 @@ module Chronic
8
8
  # @param [Hash] options Options specified in {Chronic.parse}
9
9
  # @return [Array] list of tokens
10
10
  def self.scan(tokens, options)
11
- tokens.each_index do |i|
12
- if t = scan_for_all(tokens[i]) then tokens[i].tag(t); next end
11
+ tokens.each do |token|
12
+ if t = scan_for_all(token) then token.tag(t); next end
13
13
  end
14
14
  end
15
15
 
@@ -274,6 +274,12 @@ class TestParsing < Test::Unit::TestCase
274
274
  time = parse_now("13:45")
275
275
  assert_equal Time.local(2006, 8, 17, 13, 45), time
276
276
 
277
+ time = parse_now("1:01pm")
278
+ assert_equal Time.local(2006, 8, 16, 13, 01), time
279
+
280
+ time = parse_now("2:01pm")
281
+ assert_equal Time.local(2006, 8, 16, 14, 01), time
282
+
277
283
  time = parse_now("november")
278
284
  assert_equal Time.local(2006, 11, 16), time
279
285
  end
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chronic
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.4.2
4
+ hash: 9
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 4
9
+ - 3
10
+ version: 0.4.3
6
11
  platform: ruby
7
12
  authors:
8
13
  - Tom Preston-Werner
@@ -11,7 +16,8 @@ autorequire:
11
16
  bindir: bin
12
17
  cert_chain: []
13
18
 
14
- date: 2011-06-07 00:00:00 Z
19
+ date: 2011-06-08 00:00:00 +01:00
20
+ default_executable:
15
21
  dependencies: []
16
22
 
17
23
  description: Chronic is a natural language date/time parser written in pure Ruby.
@@ -27,6 +33,8 @@ extra_rdoc_files:
27
33
  - HISTORY.md
28
34
  - LICENSE
29
35
  files:
36
+ - .gitignore
37
+ - .yardopts
30
38
  - HISTORY.md
31
39
  - LICENSE
32
40
  - Manifest.txt
@@ -86,6 +94,7 @@ files:
86
94
  - test/test_Time.rb
87
95
  - test/test_Token.rb
88
96
  - test/test_parsing.rb
97
+ has_rdoc: true
89
98
  homepage: http://github.com/mojombo/chronic
90
99
  licenses: []
91
100
 
@@ -99,21 +108,28 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
108
  requirements:
100
109
  - - ">="
101
110
  - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
102
114
  version: "0"
103
115
  required_rubygems_version: !ruby/object:Gem::Requirement
104
116
  none: false
105
117
  requirements:
106
118
  - - ">="
107
119
  - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
108
123
  version: "0"
109
124
  requirements: []
110
125
 
111
126
  rubyforge_project: chronic
112
- rubygems_version: 1.8.2
127
+ rubygems_version: 1.3.7
113
128
  signing_key:
114
129
  specification_version: 3
115
130
  summary: Natural language date/time parsing.
116
131
  test_files:
132
+ - test/helper.rb
117
133
  - test/test_Chronic.rb
118
134
  - test/test_DaylightSavings.rb
119
135
  - test/test_Handler.rb