pseudo_date 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 62d190d71ddd979da81fbea52eb5e2df961dcb4c
4
- data.tar.gz: ec4fe5b5c8739ad59631bce20bb5bfd320a57b2e
2
+ SHA256:
3
+ metadata.gz: 194f7ad213e4723e13dadd0bb7e4808b0e7d078d96302f27e67c926a471740a7
4
+ data.tar.gz: 5924349cb3530554acc4778d3983351afecb4f22a413906555259b3a70a008b8
5
5
  SHA512:
6
- metadata.gz: 7fb8dd8c6bc227e74d89190d8870071235823db1b6810acc8596eed61b5ae4745e7960ad57b6f76fec45f76375858d0f8385c2361d8a78de9cde91c8a7cdf5a3
7
- data.tar.gz: 2298c31062c1295cca27a575e977a82b7e1b881eddf2f0dfb2858dffbbcd6d09eea2cb358b3f48a3348ec140336d70236702a3f9fda96ed88fbbaa30c6c1119e
6
+ metadata.gz: 6af99fbd3a7e1a14c4e0966e145e60abd25242b9bc127e24304134eee90a35c66224878da002fb8f7e168d61065cdf22b7ed99c4ab56d3e134d13e7ef56e9a1f
7
+ data.tar.gz: f18fde6cdade727c95c9768a713a664dc4842a80afc8e4d464c2c44d02d78d30b4cf83930a0359b22f03772f2f9a464ed79227844995412ee8ee27024277161c
data/Gemfile.lock CHANGED
@@ -1,16 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pseudo_date (0.1.6)
4
+ pseudo_date (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- byebug (3.1.2)
10
- columnize (~> 0.8)
11
- debugger-linecache (~> 1.2)
12
- columnize (0.8.9)
13
- debugger-linecache (1.2.0)
14
9
  diff-lcs (1.2.5)
15
10
  rspec (3.0.0)
16
11
  rspec-core (~> 3.0.0)
@@ -29,6 +24,8 @@ PLATFORMS
29
24
  ruby
30
25
 
31
26
  DEPENDENCIES
32
- byebug
33
27
  pseudo_date!
34
28
  rspec
29
+
30
+ BUNDLED WITH
31
+ 2.1.4
@@ -1,11 +1,11 @@
1
1
  class String
2
2
 
3
3
  def to_date_hash
4
- Parser.parse(self)
4
+ PseudoDate::Parser.parse(self)
5
5
  end
6
6
 
7
7
  def to_pseudo_date
8
8
  PseudoDate.new(self)
9
9
  end
10
10
 
11
- end
11
+ end
@@ -1,110 +1,115 @@
1
1
  require 'date'
2
- class Parser
2
+ require_relative 'pseudo_date'
3
+
4
+ class PseudoDate
5
+ class Parser
3
6
 
4
- AMERICAN_DATE_FORMAT = '%m/%d/%Y'
5
- EUROPEAN_DATE_FORMAT = '%Y-%m-%d'
6
-
7
- def self.parse(input)
8
- date_hash = {}
9
- # Minor Pre Cleanup
10
- input.strip!; input.gsub!('~','')
11
-
12
- date = parse_with_poro_date(input)
13
-
14
- if date
15
- date_hash = { :year => date.year.to_s, :month => date.month.to_s, :day => date.day.to_s }
16
- else
17
- year, month, day = parse_string(input)
18
- date_hash = { :year => year, :month => month, :day => day }
19
- end
7
+ AMERICAN_DATE_FORMAT = '%m/%d/%Y'
8
+ EUROPEAN_DATE_FORMAT = '%Y-%m-%d'
20
9
 
21
- # Post parsing cleanup
22
- date_hash.each do |key, value|
23
- date_hash[key] = if value.nil?
24
- key.to_s == 'year' ? '0000' : '00'
10
+ def self.parse(input)
11
+ date_hash = {}
12
+ # Minor Pre Cleanup
13
+ input.strip!; input.gsub!('~','')
14
+
15
+ date = parse_with_poro_date(input)
16
+
17
+ if date
18
+ date_hash = { :year => date.year.to_s, :month => date.month.to_s, :day => date.day.to_s }
25
19
  else
26
- date_hash[key] = value.to_s.strip
20
+ year, month, day = parse_string(input)
21
+ date_hash = { :year => year, :month => month, :day => day }
27
22
  end
28
- end
29
-
30
- # Cleanup the single digit values
31
- unless date_hash.empty?
32
- date_hash.each do |key,value|
33
- date_hash[key] = "0#{value}" if value.to_s.length == 1
23
+
24
+ # Post parsing cleanup
25
+ date_hash.each do |key, value|
26
+ date_hash[key] = if value.nil?
27
+ key.to_s == 'year' ? '0000' : '00'
28
+ else
29
+ date_hash[key] = value.to_s.strip
30
+ end
34
31
  end
32
+
33
+ # Cleanup the single digit values
34
+ unless date_hash.empty?
35
+ date_hash.each do |key,value|
36
+ date_hash[key] = "0#{value}" if value.to_s.length == 1
37
+ end
38
+ end
39
+
40
+ # Two character years
41
+ if date_hash[:year].length == 2
42
+ date_hash[:year] = date_hash[:year].to_i > Date.today.year.to_s.slice(2..4).to_i ? "19#{date_hash[:year]}" : "20#{date_hash[:year]}"
43
+ end
44
+
45
+ # Attempt to correct some known OCR issues
46
+ if date_hash[:year].to_s.match('00') && date_hash[:year] != '0000'
47
+ date_hash[:year] = "2#{date_hash[:year].slice(1..3)}"
48
+ end
49
+
50
+ return date_hash.empty? ? nil : date_hash
35
51
  end
36
52
 
37
- # Two character years
38
- if date_hash[:year].length == 2
39
- date_hash[:year] = date_hash[:year].to_i > Date.today.year.to_s.slice(2..4).to_i ? "19#{date_hash[:year]}" : "20#{date_hash[:year]}"
40
- end
41
-
42
- # Attempt to correct some known OCR issues
43
- if date_hash[:year].to_s.match('00') && date_hash[:year] != '0000'
44
- date_hash[:year] = "2#{date_hash[:year].slice(1..3)}"
45
- end
53
+ private
46
54
 
47
- return date_hash.empty? ? nil : date_hash
48
- end
49
-
50
- private
51
-
52
- def self.parse_with_poro_date(string)
53
- # If our date has 3 parts then let's try to parse it with Date::strptime
54
- if string.split(/\/|-/).length < 3
55
- case string
56
- when /-/ # Europeans generally use hyphens to separate date pieces
57
- Date.strptime(string, EUROPEAN_DATE_FORMAT)
58
- when /\// # Americans usually use a / to separate date pieces
59
- Date.strptime(string, AMERICAN_DATE_FORMAT)
55
+ def self.parse_with_poro_date(string)
56
+ # If our date has 3 parts then let's try to parse it with Date::strptime
57
+ if string.split(/\/|-/).length < 3
58
+ case string
59
+ when /-/ # Europeans generally use hyphens to separate date pieces
60
+ Date.strptime(string, EUROPEAN_DATE_FORMAT)
61
+ when /\// # Americans usually use a / to separate date pieces
62
+ Date.strptime(string, AMERICAN_DATE_FORMAT)
63
+ end
64
+ else
65
+ nil # Not enough parts so just return nil
60
66
  end
61
- else
62
- nil # Not enough parts so just return nil
67
+ rescue
68
+ nil # We don't actually care why Date is complaining. We'll fall back to slower parsing later.
63
69
  end
64
- rescue
65
- nil # We don't actually care why Date is complaining. We'll fall back to slower parsing later.
66
- end
67
-
68
- def self.parse_string(input)
69
- day, month, year = "00", "00", "0000"
70
- if input.match('/') # 02/25/2008
71
- date_array = input.split('/')
72
- if date_array.length == 3
73
- begin
74
- parsed_date = Date.parse(self)
75
- month, day, year = parsed_date.month, parsed_date.day, parsed_date.year
76
- rescue
77
- month, day, year = date_array
70
+
71
+ def self.parse_string(input)
72
+ day, month, year = "00", "00", "0000"
73
+ if input.match('/') # 02/25/2008
74
+ date_array = input.split('/')
75
+ if date_array.length == 3
76
+ begin
77
+ parsed_date = Date.parse(self)
78
+ month, day, year = parsed_date.month, parsed_date.day, parsed_date.year
79
+ rescue
80
+ month, day, year = date_array
81
+ end
82
+ elsif date_array.length == 2
83
+ month, year = date_array
78
84
  end
79
- elsif date_array.length == 2
80
- month, year = date_array
81
- end
82
- elsif input.length == 8 && is_numeric?(input) # 20080225
83
- year, month, day = input.slice(0..3), input.slice(4..5), input.slice(6..7)
84
- elsif input.match('-') # 1985-09-25 or 02-25-2008
85
- date_array = input.split('-')
86
- year = date_array.select{ |part| part.length == 4 }.first
87
- unless year.nil? || date_array.length != 3
88
- if date_array.first == year
89
- month = date_array.last
90
- day = date_array[1]
91
- else
92
- month = date_array.first
93
- day = date_array[1]
85
+ elsif input.length == 8 && is_numeric?(input) # 20080225
86
+ year, month, day = input.slice(0..3), input.slice(4..5), input.slice(6..7)
87
+ elsif input.match('-') # 1985-09-25 or 02-25-2008
88
+ date_array = input.split('-')
89
+ year = date_array.select{ |part| part.length == 4 }.first
90
+ unless year.nil? || date_array.length != 3
91
+ if date_array.first == year
92
+ month = date_array.last
93
+ day = date_array[1]
94
+ else
95
+ month = date_array.first
96
+ day = date_array[1]
97
+ end
98
+ month, day = [day, month] if month.to_i > 12 && month.to_i > day.to_i
94
99
  end
95
- month, day = [day, month] if month.to_i > 12 && month.to_i > day.to_i
100
+ elsif input.length == 4 # 2004
101
+ year = input.to_s
102
+ elsif input.length == 2 # 85
103
+ year = (input.to_i > Date.today.year.to_s.slice(2..4).to_i) ? "19#{input}" : "20#{input}"
104
+ elsif input.match(/\w/) # Jun 23, 2004
105
+ begin
106
+ d = Date.parse(input)
107
+ year, month, day = d.year.to_s, d.month.to_s, d.day.to_s
108
+ rescue; end
96
109
  end
97
- elsif input.length == 4 # 2004
98
- year = input.to_s
99
- elsif input.length == 2 # 85
100
- year = (input.to_i > Date.today.year.to_s.slice(2..4).to_i) ? "19#{input}" : "20#{input}"
101
- elsif input.match(/\w/) # Jun 23, 2004
102
- begin
103
- d = Date.parse(input)
104
- year, month, day = d.year.to_s, d.month.to_s, d.day.to_s
105
- rescue; end
110
+ return [year, month, day]
106
111
  end
107
- return [year, month, day]
112
+
108
113
  end
109
-
110
- end
114
+
115
+ end
@@ -1,3 +1,3 @@
1
1
  class PseudoDate
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/pseudo_date.gemspec CHANGED
@@ -17,7 +17,6 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
  gem.license = 'MIT'
20
-
21
- gem.add_development_dependency("rspec", "~> 0")
22
- gem.add_development_dependency("byebug", "~> 0")
20
+
21
+ gem.add_development_dependency("rspec")
23
22
  end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,9 @@
1
1
  require 'rubygems'
2
2
  require 'rspec'
3
3
  require File.dirname(__FILE__) + '/../lib/pseudo_date'
4
- require 'byebug'
5
4
 
6
5
  RSpec.configure do |config|
7
6
  config.expect_with :rspec do |c|
8
7
  c.syntax = :should
9
8
  end
10
- end
9
+ end
metadata CHANGED
@@ -1,41 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pseudo_date
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Tulskie
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-19 00:00:00.000000000 Z
11
+ date: 2022-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: byebug
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
24
+ - - ">="
39
25
  - !ruby/object:Gem::Version
40
26
  version: '0'
41
27
  description: Date parser and container for partial or incomplete dates.
@@ -66,7 +52,7 @@ homepage: http://github.com/PatrickTulskie/pseudo_date
66
52
  licenses:
67
53
  - MIT
68
54
  metadata: {}
69
- post_install_message:
55
+ post_install_message:
70
56
  rdoc_options: []
71
57
  require_paths:
72
58
  - lib
@@ -81,9 +67,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
83
69
  requirements: []
84
- rubyforge_project:
85
- rubygems_version: 2.2.2
86
- signing_key:
70
+ rubygems_version: 3.2.3
71
+ signing_key:
87
72
  specification_version: 4
88
73
  summary: Date parser and container for partial or incomplete dates.
89
74
  test_files: