smarter_dates 0.2.7.8 → 0.2.7.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -1
- data/Gemfile +4 -0
- data/Rakefile +1 -43
- data/lib/smarter_dates/parser.rb +57 -0
- data/lib/smarter_dates/version.rb +4 -0
- data/lib/smarter_dates.rb +2 -58
- data/smarter_dates.gemspec +15 -44
- data/test/smarter_dates_test.rb +6 -2
- metadata +20 -18
data/.gitignore
CHANGED
data/Gemfile
ADDED
data/Rakefile
CHANGED
@@ -1,43 +1 @@
|
|
1
|
-
require '
|
2
|
-
require 'rake/testtask'
|
3
|
-
require 'rake/rdoctask'
|
4
|
-
|
5
|
-
desc 'Default: run unit tests.'
|
6
|
-
task :default => :test
|
7
|
-
|
8
|
-
desc 'Test the smarter_dates gem.'
|
9
|
-
Rake::TestTask.new(:test) do |t|
|
10
|
-
t.libs << 'lib'
|
11
|
-
t.libs << 'test'
|
12
|
-
t.pattern = 'test/**/*_test.rb'
|
13
|
-
t.verbose = true
|
14
|
-
end
|
15
|
-
|
16
|
-
desc 'Generate documentation for the smarter_dates gem.'
|
17
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
-
rdoc.rdoc_dir = 'rdoc'
|
19
|
-
rdoc.title = 'SmarterDates'
|
20
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
-
rdoc.rdoc_files.include('README.rdoc')
|
22
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
-
end
|
24
|
-
|
25
|
-
begin
|
26
|
-
require 'jeweler'
|
27
|
-
Jeweler::Tasks.new do |gemspec|
|
28
|
-
gemspec.name = 'smarter_dates'
|
29
|
-
gemspec.summary = 'machina to automatically parse date/datetime attributes upon assignment.'
|
30
|
-
gemspec.description = "Humans want to think of date and datetime attributes in a natural manner.\nStandard ruby Date and DateTime objects do not support this well."
|
31
|
-
gemspec.email = 'Paul Belt'
|
32
|
-
gemspec.authors = ['Paul Belt']
|
33
|
-
gemspec.homepage = 'http://github.com/belt/smarter_dates'
|
34
|
-
gemspec.extra_rdoc_files = ['README.rdoc']
|
35
|
-
gemspec.rdoc_options = ['--charset=UTF-8']
|
36
|
-
gemspec.add_dependency('chronic', '~> 0.2.3')
|
37
|
-
gemspec.rubyforge_project = 'smarter_dates'
|
38
|
-
end
|
39
|
-
Jeweler::GemcutterTasks.new
|
40
|
-
rescue LoadError
|
41
|
-
puts "Jeweler not available. Install it with: gem install jeweler"
|
42
|
-
end
|
43
|
-
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'smarter_dates/version'
|
2
|
+
require 'chronic'
|
3
|
+
|
4
|
+
module SmarterDates
|
5
|
+
def self.included( klass ) # :nodoc:
|
6
|
+
attr_accessor :dt_attributes
|
7
|
+
|
8
|
+
@dt_attributes = []
|
9
|
+
db_migrated = true
|
10
|
+
if defined?(Rails)
|
11
|
+
begin
|
12
|
+
@dt_attributes.concat(klass.column_names.select{|k|k.match(/_(?:at|on|dt|d)$/)})
|
13
|
+
Rails.logger.debug(RuntimeError,"unused include - #{klass.class.to_s} does not have any attributes ending in _at, _on, _dt, or _d") if db_migrated && @dt_attributes.empty?
|
14
|
+
rescue ActiveRecord::StatementInvalid => e
|
15
|
+
db_migrated = false
|
16
|
+
rescue => e
|
17
|
+
Rails.logger.debug(e.inspect)
|
18
|
+
db_migrated = false
|
19
|
+
end
|
20
|
+
else
|
21
|
+
@dt_attributes.concat(klass.instance_methods.select{|k|k.match(/_(?:at|on|dt|d)$/)})
|
22
|
+
end
|
23
|
+
|
24
|
+
# :call-seq:
|
25
|
+
# _on(string)
|
26
|
+
# _at(string)
|
27
|
+
# _dt(string)
|
28
|
+
# _d(string)
|
29
|
+
#
|
30
|
+
# Any attribute ending in _at, _on, _dt, or _d are parsed by Chronic.parse
|
31
|
+
# (for flexibility). Values are passed as is to Chronic.parse()
|
32
|
+
#
|
33
|
+
# == Arguments
|
34
|
+
# <tt>string</tt>:: A string
|
35
|
+
|
36
|
+
@dt_attributes.each do |k|
|
37
|
+
parse = Proc.new do |val|
|
38
|
+
begin
|
39
|
+
dt = Chronic.parse(val.to_s)
|
40
|
+
rescue
|
41
|
+
dt = DateTime.parse(val)
|
42
|
+
rescue
|
43
|
+
dt = Date.parse(val)
|
44
|
+
rescue
|
45
|
+
dt = val
|
46
|
+
end
|
47
|
+
if defined?(Rails)
|
48
|
+
self[k] = dt
|
49
|
+
else
|
50
|
+
instance_variable_set(:"@#{k}",dt)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
klass.send(:define_method, "#{k}=".to_sym, &parse)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
data/lib/smarter_dates.rb
CHANGED
@@ -1,59 +1,3 @@
|
|
1
|
-
|
2
|
-
require '
|
3
|
-
|
4
|
-
def self.included( klass ) # :nodoc:
|
5
|
-
dt_attributes = []
|
6
|
-
db_migrated = true
|
7
|
-
if defined?(Rails)
|
8
|
-
begin
|
9
|
-
dt_attributes.concat(klass.column_names.select{|k|k.match(/_(?:at|on|dt|d)$/)})
|
10
|
-
Rails.logger.debug(RuntimeError,"unused include - #{klass.class.to_s} does not have any attributes ending in _at, _on, _dt, or _d") if db_migrated && dt_attributes.empty?
|
11
|
-
rescue ActiveRecord::StatementInvalid => e
|
12
|
-
db_migrated = false
|
13
|
-
rescue => e
|
14
|
-
Rails.logger.debug(e.inspect)
|
15
|
-
db_migrated = false
|
16
|
-
end
|
17
|
-
else
|
18
|
-
dt_attributes.concat(klass.instance_methods.select{|k|k.match(/_(?:at|on|dt|d)$/)})
|
19
|
-
end
|
20
|
-
|
21
|
-
# :call-seq:
|
22
|
-
# _on(string)
|
23
|
-
# _at(string)
|
24
|
-
# _dt(string)
|
25
|
-
# _d(string)
|
26
|
-
#
|
27
|
-
# Any attribute ending in _at, _on, _dt, or _d are parsed by Chronic.parse
|
28
|
-
# (for flexibility). Values are passed as is to Chronic.parse()
|
29
|
-
#
|
30
|
-
# == Arguments
|
31
|
-
# <tt>string</tt>:: A string
|
32
|
-
|
33
|
-
dt_attributes.each do |k|
|
34
|
-
parse = Proc.new do |val|
|
35
|
-
begin
|
36
|
-
dt = Chronic.parse(val.to_s(:db))
|
37
|
-
rescue
|
38
|
-
dt = Chronic.parse(val.to_s)
|
39
|
-
rescue
|
40
|
-
dt = DateTime.parse(val)
|
41
|
-
rescue
|
42
|
-
dt = Date.parse(val)
|
43
|
-
rescue
|
44
|
-
dt = val
|
45
|
-
end
|
46
|
-
|
47
|
-
if respond_to?(:write_attribute)
|
48
|
-
write_attribute(k,dt)
|
49
|
-
else
|
50
|
-
instance_variable_set(:"@#{k}",dt)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
klass.send(:define_method, "#{k}=".to_sym, &parse)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# /module
|
58
|
-
end
|
1
|
+
require File.join('smarter_dates','version')
|
2
|
+
require File.join('smarter_dates','parser')
|
59
3
|
|
data/smarter_dates.gemspec
CHANGED
@@ -1,52 +1,23 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'smarter_dates/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
6
|
+
s.name = 'smarter_dates'
|
7
|
+
s.version = SmarterDates::VERSION
|
8
|
+
s.authors = ['Paul Belt']
|
9
|
+
s.email = ['paul.belt@gmail.com']
|
10
|
+
s.homepage = 'http://github.com/belt/smarter_dates'
|
11
|
+
s.summary = %q{Natural language date processing}
|
12
|
+
s.description = %q{Humans want to think of date and datetime attributes in a natural manner. Standard ruby Date and DateTime objects do not support this well.}
|
9
13
|
|
10
|
-
s.
|
11
|
-
s.authors = ["Paul Belt"]
|
12
|
-
s.date = %q{2010-10-20}
|
13
|
-
s.description = %q{Humans want to think of date and datetime attributes in a natural manner.
|
14
|
-
Standard ruby Date and DateTime objects do not support this well.}
|
15
|
-
s.email = %q{Paul Belt}
|
16
|
-
s.extra_rdoc_files = [
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".gitignore",
|
21
|
-
"LICENSE",
|
22
|
-
"README.rdoc",
|
23
|
-
"Rakefile",
|
24
|
-
"VERSION.yml",
|
25
|
-
"lib/smarter_dates.rb",
|
26
|
-
"smarter_dates.gemspec",
|
27
|
-
"test/smarter_dates_test.rb"
|
28
|
-
]
|
29
|
-
s.homepage = %q{http://github.com/belt/smarter_dates}
|
30
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
31
|
-
s.require_paths = ["lib"]
|
32
|
-
s.rubyforge_project = %q{smarter_dates}
|
33
|
-
s.rubygems_version = %q{1.3.7}
|
34
|
-
s.summary = %q{machina to automatically parse date/datetime attributes upon assignment.}
|
35
|
-
s.test_files = [
|
36
|
-
"test/smarter_dates_test.rb"
|
37
|
-
]
|
14
|
+
s.rubyforge_project = 'smarter_dates'
|
38
15
|
|
39
|
-
|
40
|
-
|
41
|
-
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ['lib']
|
42
20
|
|
43
|
-
|
44
|
-
s.add_runtime_dependency(%q<chronic>, ["~> 0.2.3"])
|
45
|
-
else
|
46
|
-
s.add_dependency(%q<chronic>, ["~> 0.2.3"])
|
47
|
-
end
|
48
|
-
else
|
49
|
-
s.add_dependency(%q<chronic>, ["~> 0.2.3"])
|
50
|
-
end
|
21
|
+
s.add_dependency('chronic', '~> 0.3.0')
|
51
22
|
end
|
52
23
|
|
data/test/smarter_dates_test.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'test/unit'
|
3
|
-
|
2
|
+
|
3
|
+
if $LOAD_PATH.include?(File.expand_path(File.join(File.dirname(__FILE__),'..','lib')))
|
4
|
+
require 'smarter_dates'
|
5
|
+
else
|
6
|
+
raise RuntimeError, "Try ruby -Ilib test/#{File.basename(__FILE__)}"
|
7
|
+
end
|
4
8
|
|
5
9
|
class Model
|
6
10
|
attr_accessor :name
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smarter_dates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 81
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
9
|
- 7
|
10
|
-
-
|
11
|
-
version: 0.2.7.
|
10
|
+
- 9
|
11
|
+
version: 0.2.7.9
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Paul Belt
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2011-06-27 00:00:00 -04:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -27,31 +27,33 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
hash:
|
30
|
+
hash: 19
|
31
31
|
segments:
|
32
32
|
- 0
|
33
|
-
- 2
|
34
33
|
- 3
|
35
|
-
|
34
|
+
- 0
|
35
|
+
version: 0.3.0
|
36
36
|
type: :runtime
|
37
37
|
version_requirements: *id001
|
38
|
-
description:
|
39
|
-
|
40
|
-
|
41
|
-
email: Paul Belt
|
38
|
+
description: Humans want to think of date and datetime attributes in a natural manner. Standard ruby Date and DateTime objects do not support this well.
|
39
|
+
email:
|
40
|
+
- paul.belt@gmail.com
|
42
41
|
executables: []
|
43
42
|
|
44
43
|
extensions: []
|
45
44
|
|
46
|
-
extra_rdoc_files:
|
47
|
-
|
45
|
+
extra_rdoc_files: []
|
46
|
+
|
48
47
|
files:
|
49
48
|
- .gitignore
|
49
|
+
- Gemfile
|
50
50
|
- LICENSE
|
51
51
|
- README.rdoc
|
52
52
|
- Rakefile
|
53
53
|
- VERSION.yml
|
54
54
|
- lib/smarter_dates.rb
|
55
|
+
- lib/smarter_dates/parser.rb
|
56
|
+
- lib/smarter_dates/version.rb
|
55
57
|
- smarter_dates.gemspec
|
56
58
|
- test/smarter_dates_test.rb
|
57
59
|
has_rdoc: true
|
@@ -59,8 +61,8 @@ homepage: http://github.com/belt/smarter_dates
|
|
59
61
|
licenses: []
|
60
62
|
|
61
63
|
post_install_message:
|
62
|
-
rdoc_options:
|
63
|
-
|
64
|
+
rdoc_options: []
|
65
|
+
|
64
66
|
require_paths:
|
65
67
|
- lib
|
66
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -84,9 +86,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
86
|
requirements: []
|
85
87
|
|
86
88
|
rubyforge_project: smarter_dates
|
87
|
-
rubygems_version: 1.
|
89
|
+
rubygems_version: 1.6.2
|
88
90
|
signing_key:
|
89
91
|
specification_version: 3
|
90
|
-
summary:
|
92
|
+
summary: Natural language date processing
|
91
93
|
test_files:
|
92
94
|
- test/smarter_dates_test.rb
|