Hokkaido 0.0.3 → 0.0.4

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 (84) hide show
  1. data/Gemfile +2 -0
  2. data/Gemfile.lock +2 -2
  3. data/ansiterm-color/.gitignore +3 -0
  4. data/ansiterm-color/CHANGES +28 -0
  5. data/ansiterm-color/COPYING +340 -0
  6. data/ansiterm-color/README +137 -0
  7. data/ansiterm-color/Rakefile +88 -0
  8. data/ansiterm-color/VERSION +1 -0
  9. data/ansiterm-color/bin/cdiff +19 -0
  10. data/ansiterm-color/bin/decolor +12 -0
  11. data/ansiterm-color/doc-main.txt +119 -0
  12. data/ansiterm-color/examples/example.rb +90 -0
  13. data/ansiterm-color/install.rb +15 -0
  14. data/ansiterm-color/lib/term/ansicolor/.keep +0 -0
  15. data/ansiterm-color/lib/term/ansicolor/version.rb +10 -0
  16. data/ansiterm-color/lib/term/ansicolor.rb +102 -0
  17. data/ansiterm-color/make_doc.rb +4 -0
  18. data/ansiterm-color/tests/ansicolor_test.rb +66 -0
  19. data/chronic/.gitignore +6 -0
  20. data/chronic/HISTORY.md +205 -0
  21. data/chronic/LICENSE +21 -0
  22. data/chronic/README.md +181 -0
  23. data/chronic/Rakefile +46 -0
  24. data/chronic/chronic.gemspec +20 -0
  25. data/chronic/lib/chronic/grabber.rb +33 -0
  26. data/chronic/lib/chronic/handler.rb +88 -0
  27. data/chronic/lib/chronic/handlers.rb +572 -0
  28. data/chronic/lib/chronic/mini_date.rb +38 -0
  29. data/chronic/lib/chronic/numerizer.rb +121 -0
  30. data/chronic/lib/chronic/ordinal.rb +47 -0
  31. data/chronic/lib/chronic/pointer.rb +32 -0
  32. data/chronic/lib/chronic/repeater.rb +145 -0
  33. data/chronic/lib/chronic/repeaters/repeater_day.rb +53 -0
  34. data/chronic/lib/chronic/repeaters/repeater_day_name.rb +52 -0
  35. data/chronic/lib/chronic/repeaters/repeater_day_portion.rb +108 -0
  36. data/chronic/lib/chronic/repeaters/repeater_fortnight.rb +71 -0
  37. data/chronic/lib/chronic/repeaters/repeater_hour.rb +58 -0
  38. data/chronic/lib/chronic/repeaters/repeater_minute.rb +58 -0
  39. data/chronic/lib/chronic/repeaters/repeater_month.rb +79 -0
  40. data/chronic/lib/chronic/repeaters/repeater_month_name.rb +94 -0
  41. data/chronic/lib/chronic/repeaters/repeater_season.rb +109 -0
  42. data/chronic/lib/chronic/repeaters/repeater_season_name.rb +43 -0
  43. data/chronic/lib/chronic/repeaters/repeater_second.rb +42 -0
  44. data/chronic/lib/chronic/repeaters/repeater_time.rb +128 -0
  45. data/chronic/lib/chronic/repeaters/repeater_week.rb +74 -0
  46. data/chronic/lib/chronic/repeaters/repeater_weekday.rb +85 -0
  47. data/chronic/lib/chronic/repeaters/repeater_weekend.rb +66 -0
  48. data/chronic/lib/chronic/repeaters/repeater_year.rb +77 -0
  49. data/chronic/lib/chronic/scalar.rb +116 -0
  50. data/chronic/lib/chronic/season.rb +26 -0
  51. data/chronic/lib/chronic/separator.rb +94 -0
  52. data/chronic/lib/chronic/span.rb +31 -0
  53. data/chronic/lib/chronic/tag.rb +36 -0
  54. data/chronic/lib/chronic/time_zone.rb +32 -0
  55. data/chronic/lib/chronic/token.rb +47 -0
  56. data/chronic/lib/chronic.rb +442 -0
  57. data/chronic/test/helper.rb +12 -0
  58. data/chronic/test/test_chronic.rb +150 -0
  59. data/chronic/test/test_daylight_savings.rb +118 -0
  60. data/chronic/test/test_handler.rb +104 -0
  61. data/chronic/test/test_mini_date.rb +32 -0
  62. data/chronic/test/test_numerizer.rb +72 -0
  63. data/chronic/test/test_parsing.rb +1061 -0
  64. data/chronic/test/test_repeater_day_name.rb +51 -0
  65. data/chronic/test/test_repeater_day_portion.rb +254 -0
  66. data/chronic/test/test_repeater_fortnight.rb +62 -0
  67. data/chronic/test/test_repeater_hour.rb +68 -0
  68. data/chronic/test/test_repeater_minute.rb +34 -0
  69. data/chronic/test/test_repeater_month.rb +50 -0
  70. data/chronic/test/test_repeater_month_name.rb +56 -0
  71. data/chronic/test/test_repeater_season.rb +40 -0
  72. data/chronic/test/test_repeater_time.rb +70 -0
  73. data/chronic/test/test_repeater_week.rb +62 -0
  74. data/chronic/test/test_repeater_weekday.rb +55 -0
  75. data/chronic/test/test_repeater_weekend.rb +74 -0
  76. data/chronic/test/test_repeater_year.rb +69 -0
  77. data/chronic/test/test_span.rb +23 -0
  78. data/chronic/test/test_token.rb +25 -0
  79. data/lib/Hokkaido/version.rb +1 -1
  80. data/lib/Hokkaido.rb +13 -9
  81. data/lib/gem_modifier.rb +23 -3
  82. data/lib/term/ansicolor.rb +4 -1
  83. data/spec/Hokkaido/port_spec.rb +15 -7
  84. metadata +78 -2
data/chronic/README.md ADDED
@@ -0,0 +1,181 @@
1
+ Chronic
2
+ =======
3
+
4
+ ## DESCRIPTION
5
+
6
+ Chronic is a natural language date/time parser written in pure Ruby. See below
7
+ for the wide variety of formats Chronic will parse.
8
+
9
+
10
+ ## INSTALLATION
11
+
12
+ ### RubyGems
13
+
14
+ $ [sudo] gem install chronic
15
+
16
+ ### GitHub
17
+
18
+ $ git clone git://github.com/mojombo/chronic.git
19
+ $ cd chronic && gem build chronic.gemspec
20
+ $ gem install chronic-<version>.gem
21
+
22
+
23
+ ## USAGE
24
+
25
+ You can parse strings containing a natural language date using the
26
+ `Chronic.parse` method.
27
+
28
+ require 'chronic'
29
+
30
+ Time.now #=> Sun Aug 27 23:18:25 PDT 2006
31
+
32
+ Chronic.parse('tomorrow')
33
+ #=> Mon Aug 28 12:00:00 PDT 2006
34
+
35
+ Chronic.parse('monday', :context => :past)
36
+ #=> Mon Aug 21 12:00:00 PDT 2006
37
+
38
+ Chronic.parse('this tuesday 5:00')
39
+ #=> Tue Aug 29 17:00:00 PDT 2006
40
+
41
+ Chronic.parse('this tuesday 5:00', :ambiguous_time_range => :none)
42
+ #=> Tue Aug 29 05:00:00 PDT 2006
43
+
44
+ Chronic.parse('may 27th', :now => Time.local(2000, 1, 1))
45
+ #=> Sat May 27 12:00:00 PDT 2000
46
+
47
+ Chronic.parse('may 27th', :guess => false)
48
+ #=> Sun May 27 00:00:00 PDT 2007..Mon May 28 00:00:00 PDT 2007
49
+
50
+ Chronic.parse('6/4/2012', :endian_precedence => :little)
51
+ #=> Fri Apr 06 00:00:00 PDT 2012
52
+
53
+
54
+ See `Chronic.parse` for detailed usage instructions.
55
+
56
+
57
+ ## EXAMPLES
58
+
59
+ Chronic can parse a huge variety of date and time formats. Following is a
60
+ small sample of strings that will be properly parsed. Parsing is case
61
+ insensitive and will handle common abbreviations and misspellings.
62
+
63
+ Simple
64
+
65
+ * thursday
66
+ * november
67
+ * summer
68
+ * friday 13:00
69
+ * mon 2:35
70
+ * 4pm
71
+ * 6 in the morning
72
+ * friday 1pm
73
+ * sat 7 in the evening
74
+ * yesterday
75
+ * today
76
+ * tomorrow
77
+ * this tuesday
78
+ * next month
79
+ * last winter
80
+ * this morning
81
+ * last night
82
+ * this second
83
+ * yesterday at 4:00
84
+ * last friday at 20:00
85
+ * last week tuesday
86
+ * tomorrow at 6:45pm
87
+ * afternoon yesterday
88
+ * thursday last week
89
+
90
+ Complex
91
+
92
+ * 3 years ago
93
+ * a year ago
94
+ * 5 months before now
95
+ * 7 hours ago
96
+ * 7 days from now
97
+ * 1 week hence
98
+ * in 3 hours
99
+ * 1 year ago tomorrow
100
+ * 3 months ago saturday at 5:00 pm
101
+ * 7 hours before tomorrow at noon
102
+ * 3rd wednesday in november
103
+ * 3rd month next year
104
+ * 3rd thursday this september
105
+ * 4th day last week
106
+ * fourteenth of june 2010 at eleven o'clock in the evening
107
+ * may seventh '97 at three in the morning
108
+
109
+ Specific Dates
110
+
111
+ * January 5
112
+ * 22nd of june
113
+ * 5th may 2017
114
+ * February twenty first
115
+ * dec 25
116
+ * may 27th
117
+ * October 2006
118
+ * oct 06
119
+ * jan 3 2010
120
+ * february 14, 2004
121
+ * february 14th, 2004
122
+ * 3 jan 2000
123
+ * 17 april 85
124
+ * 5/27/1979
125
+ * 27/5/1979
126
+ * 05/06
127
+ * 1979-05-27
128
+ * Friday
129
+ * 5
130
+ * 4:00
131
+ * 17:00
132
+ * 0800
133
+
134
+ Specific Times (many of the above with an added time)
135
+
136
+ * January 5 at 7pm
137
+ * 22nd of june at 8am
138
+ * 1979-05-27 05:00:00
139
+ * etc
140
+
141
+
142
+ ## TIME ZONES
143
+
144
+ Chronic allows you to set which Time class to use when constructing times. By
145
+ default, the built in Ruby time class creates times in your system's local
146
+ time zone. You can set this to something like ActiveSupport's
147
+ [TimeZone](http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html)
148
+ class to get full time zone support.
149
+
150
+ >> Time.zone = "UTC"
151
+ >> Chronic.time_class = Time.zone
152
+ >> Chronic.parse("June 15 2006 at 5:45 AM")
153
+ => Thu, 15 Jun 2006 05:45:00 UTC +00:00
154
+
155
+
156
+ ## LIMITATIONS
157
+
158
+ Chronic uses Ruby's built in Time class for all time storage and computation.
159
+ Because of this, only times that the Time class can handle will be properly
160
+ parsed. Parsing for times outside of this range will simply return nil.
161
+ Support for a wider range of times is planned for a future release.
162
+
163
+
164
+ ## CONTRIBUTE
165
+
166
+ If you'd like to hack on Chronic, start by forking the repo on GitHub:
167
+
168
+ https://github.com/mojombo/chronic
169
+
170
+ The best way to get your changes merged back into core is as follows:
171
+
172
+ 1. Clone down your fork
173
+ 1. Create a thoughtfully named topic branch to contain your change
174
+ 1. Hack away
175
+ 1. Add tests and make sure everything still passes by running `rake`
176
+ 1. Ensure your tests pass in multiple timezones. ie `TZ=utc rake` `TZ=BST rake`
177
+ 1. If you are adding new functionality, document it in the README
178
+ 1. Do not change the version number, we will do that on our end
179
+ 1. If necessary, rebase your commits into logical chunks, without errors
180
+ 1. Push the branch up to GitHub
181
+ 1. Send a pull request for your branch
data/chronic/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'date'
2
+
3
+ def version
4
+ contents = File.read File.expand_path('../lib/chronic.rb', __FILE__)
5
+ contents[/VERSION = "([^"]+)"/, 1]
6
+ end
7
+
8
+ task :test do
9
+ $:.unshift './test'
10
+ Dir.glob('test/test_*.rb').each { |t| require File.basename(t) }
11
+ end
12
+
13
+ desc "Generate RCov test coverage and open in your browser"
14
+ task :coverage do
15
+ require 'rcov'
16
+ sh "rm -fr coverage"
17
+ sh "rcov test/test_*.rb"
18
+ sh "open coverage/index.html"
19
+ end
20
+
21
+ desc "Open an irb session preloaded with this library"
22
+ task :console do
23
+ sh "irb -Ilib -rchronic"
24
+ end
25
+
26
+ desc "Release Chronic version #{version}"
27
+ task :release => :build do
28
+ unless `git branch` =~ /^\* master$/
29
+ puts "You must be on the master branch to release!"
30
+ exit!
31
+ end
32
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
33
+ sh "git tag v#{version}"
34
+ sh "git push origin master"
35
+ sh "git push origin v#{version}"
36
+ sh "gem push pkg/chronic-#{version}.gem"
37
+ end
38
+
39
+ desc "Build a gem from the gemspec"
40
+ task :build do
41
+ sh "mkdir -p pkg"
42
+ sh "gem build chronic.gemspec"
43
+ sh "mv chronic-#{version}.gem pkg"
44
+ end
45
+
46
+ task :default => :test
@@ -0,0 +1,20 @@
1
+ $:.unshift File.expand_path('../lib', __FILE__)
2
+ require 'chronic'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'chronic'
6
+ s.version = Chronic::VERSION
7
+ s.rubyforge_project = 'chronic'
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']
11
+ s.email = ['tom@mojombo.com', 'lee@jarvis.co']
12
+ s.homepage = 'http://github.com/mojombo/chronic'
13
+ s.rdoc_options = ['--charset=UTF-8']
14
+ s.extra_rdoc_files = %w[README.md HISTORY.md LICENSE]
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- test`.split("\n")
17
+
18
+ s.add_development_dependency 'rake'
19
+ s.add_development_dependency 'minitest'
20
+ end
@@ -0,0 +1,33 @@
1
+ module Chronic
2
+ class Grabber < Tag
3
+
4
+ # Scan an Array of Tokens and apply any necessary Grabber tags to
5
+ # each token.
6
+ #
7
+ # tokens - An Array of Token objects to scan.
8
+ # options - The Hash of options specified in Chronic::parse.
9
+ #
10
+ # Returns an Array of Token objects.
11
+ def self.scan(tokens, options)
12
+ tokens.each do |token|
13
+ if t = scan_for_all(token) then token.tag(t); next end
14
+ end
15
+ end
16
+
17
+ # token - The Token object to scan.
18
+ #
19
+ # Returns a new Grabber object.
20
+ def self.scan_for_all(token)
21
+ scan_for token, self,
22
+ {
23
+ /last/ => :last,
24
+ /this/ => :this,
25
+ /next/ => :next
26
+ }
27
+ end
28
+
29
+ def to_s
30
+ 'grabber-' << @type.to_s
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,88 @@
1
+ module Chronic
2
+ class Handler
3
+
4
+ attr_reader :pattern
5
+
6
+ attr_reader :handler_method
7
+
8
+ # pattern - An Array of patterns to match tokens against.
9
+ # handler_method - A Symbole representing the method to be invoked
10
+ # when patterns are matched.
11
+ def initialize(pattern, handler_method)
12
+ @pattern = pattern
13
+ @handler_method = handler_method
14
+ end
15
+
16
+ # tokens - An Array of tokens to process.
17
+ # definitions - A Hash of definitions to check against.
18
+ #
19
+ # Returns true if a match is found.
20
+ def match(tokens, definitions)
21
+ token_index = 0
22
+
23
+ @pattern.each do |element|
24
+ name = element.to_s
25
+ optional = name[-1, 1] == '?'
26
+ name = name.chop if optional
27
+
28
+ case element
29
+ when Symbol
30
+ if tags_match?(name, tokens, token_index)
31
+ token_index += 1
32
+ next
33
+ else
34
+ if optional
35
+ next
36
+ else
37
+ return false
38
+ end
39
+ end
40
+ when String
41
+ return true if optional && token_index == tokens.size
42
+
43
+ if definitions.key?(name.to_sym)
44
+ sub_handlers = definitions[name.to_sym]
45
+ else
46
+ raise ChronicPain, "Invalid subset #{name} specified"
47
+ end
48
+
49
+ sub_handlers.each do |sub_handler|
50
+ return true if sub_handler.match(tokens[token_index..tokens.size], definitions)
51
+ end
52
+ else
53
+ raise ChronicPain, "Invalid match type: #{element.class}"
54
+ end
55
+ end
56
+
57
+ return false if token_index != tokens.size
58
+ return true
59
+ end
60
+
61
+ def invoke(type, tokens, options)
62
+ if Chronic.debug
63
+ puts "-#{type}"
64
+ puts "Handler: #{@handler_method}"
65
+ end
66
+
67
+ Handlers.send(@handler_method, tokens, options)
68
+ end
69
+
70
+ # other - The other Handler object to compare.
71
+ #
72
+ # Returns true if these Handlers match.
73
+ def ==(other)
74
+ @pattern == other.pattern
75
+ end
76
+
77
+ private
78
+
79
+ def tags_match?(name, tokens, token_index)
80
+ klass = Chronic.const_get(name.to_s.gsub(/(?:^|_)(.)/) { $1.upcase })
81
+
82
+ if tokens[token_index]
83
+ !tokens[token_index].tags.select { |o| o.kind_of?(klass) }.empty?
84
+ end
85
+ end
86
+
87
+ end
88
+ end