reckon 0.9.3 → 0.9.4

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
2
  SHA256:
3
- metadata.gz: bc9cf03c584638f19ffd111497105288a9002a71ec4dd649655a7fa1b8c6566c
4
- data.tar.gz: 75453fe81b3f131a72dae8ab1f592cf0bcfb61fb380c5486cb984ffb504fa64b
3
+ metadata.gz: 648b51c8481100983f8d8eff4d9b86ea2ad1962e0908268a6450f618d90f3267
4
+ data.tar.gz: fb19e70b53da00299caa495e24d8fa01ac20686306e383f598a8888f5118dae3
5
5
  SHA512:
6
- metadata.gz: 9cc31d230176f3d70609d7560ce5b948295d3eef33402ea12aa91749ecb48cf4c36e9885af4ea07e451c8641ae1acacd5421b093621cbde65f88da116992be30
7
- data.tar.gz: d4e743fa0f3104bc4fe14774ea5e7ce8b7862c0865b725f6e7fac5f0a68607c7baa45c95a99d755c46a03dd90389d69e6addfd06c990103e4bc12c9959e6bf65
6
+ metadata.gz: 56a4558fe3aadfbf9a0a9f4399f8e70b549b90a08057235fafe5839203390c462b502511fc60b748490398c75f46b5a4d8ccbb4ac9b07b4e6058d72bf615f4ac
7
+ data.tar.gz: dc3acb9fdae98efc8cd4a8891037cc5bfff716b2c5db74f8b1f86edaa2da0e60843ffbcb0eeeef49358738e0a63bded19e2fa3f9955cce40566a3241cbc86aff
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- reckon (0.9.3)
4
+ reckon (0.9.4)
5
5
  chronic (>= 0.3.0)
6
6
  highline (>= 1.5.2)
7
7
  matrix (>= 0.4.2)
@@ -81,12 +81,15 @@ module Reckon
81
81
  date_score += 30 if entry =~ /^\d+[:\/\.-]\d+[:\/\.-]\d+([ :]\d+[:\/\.]\d+)?$/
82
82
  date_score += 10 if entry =~ /^\d+\[\d+:GMT\]$/i
83
83
 
84
+ # ruby 2.6.0 doesn't have Date::Error, but Date::Error is a subclass of
85
+ # ArgumentError
86
+ #
87
+ # Sometimes DateTime.parse can throw a RangeError
88
+ # See https://github.com/cantino/reckon/issues/126
84
89
  begin
85
90
  DateTime.parse(entry)
86
91
  date_score += 20
87
- # ruby 2.6.0 doesn't have Date::Error, but Date::Error is a subclass of
88
- # ArgumentError
89
- rescue ArgumentError
92
+ rescue StandardError
90
93
  # we don't need do anything here since the column didn't parse as a date
91
94
  nil
92
95
  end
@@ -1,3 +1,3 @@
1
1
  module Reckon
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
  end
@@ -1,59 +1,72 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: utf-8
2
+ # frozen_string_literal: true
3
3
 
4
4
  require "spec_helper"
5
- require 'rubygems'
6
- require 'reckon'
7
-
8
- describe Reckon::DateColumn do
9
- describe "initialize" do
10
- it "should detect us and world time" do
11
- Reckon::DateColumn.new( ["01/02/2013", "01/14/2013"] ).endian_precedence.should == [:middle]
12
- Reckon::DateColumn.new( ["01/02/2013", "14/01/2013"] ).endian_precedence.should == [:little]
13
- end
14
- it "should set endian_precedence to default when date format cannot be misinterpreted" do
15
- Reckon::DateColumn.new( ["2013/01/02"] ).endian_precedence.should == [:middle,:little]
16
- end
17
- it "should raise an error when in doubt" do
18
- expect{ Reckon::DateColumn.new( ["01/02/2013", "01/03/2013"] )}.to raise_error( StandardError )
19
- end
20
- end
21
- describe "for" do
22
- it "should detect the date" do
23
- expect(Reckon::DateColumn.new(%w[13/12/2013]).for(0))
24
- .to eq(Date.new(2013, 12, 13))
25
- expect(Reckon::DateColumn.new(%w[01/14/2013]).for(0))
26
- .to eq(Date.new(2013, 1, 14))
27
- expect(Reckon::DateColumn.new(%w[13/12/2013 21/11/2013]).for(1))
28
- .to eq(Date.new(2013, 11, 21))
29
- expect(Reckon::DateColumn.new( ["2013-11-21"] ).for( 0 ))
30
- .to eq(Date.new(2013, 11, 21))
5
+ require "rubygems"
6
+ require "reckon"
31
7
 
8
+ # datecolumn specs
9
+ module Reckon
10
+ describe DateColumn do
11
+ describe "#initialize" do
12
+ it "should detect us and world time" do
13
+ expect(DateColumn.new(%w[01/02/2013 01/14/2013]).endian_precedence)
14
+ .to eq [:middle]
15
+ expect(DateColumn.new(%w[01/02/2013 14/01/2013]).endian_precedence)
16
+ .to eq [:little]
17
+ end
18
+ it "should set endian_precedence to default when date format cannot be misinterpreted" do
19
+ expect(DateColumn.new(["2013/01/02"]).endian_precedence)
20
+ .to eq %i[middle little]
21
+ end
22
+ it "should raise an error when in doubt" do
23
+ expect { DateColumn.new(["01/02/2013", "01/03/2013"]) }
24
+ .to raise_error(StandardError)
25
+ end
32
26
  end
33
27
 
34
- it "should correctly use endian_precedence" do
35
- expect(Reckon::DateColumn.new(%w[01/02/2013 01/14/2013]).for(0))
36
- .to eq(Date.new(2013, 1, 2))
37
- expect(Reckon::DateColumn.new(%w[01/02/2013 14/01/2013]).for(0))
38
- .to eq(Date.new(2013, 2, 1))
39
- end
40
- end
28
+ describe "#for" do
29
+ it "should detect the date" do
30
+ expect(DateColumn.new(%w[13/12/2013]).for(0)).to eq(Date.new(2013, 12, 13))
31
+ expect(DateColumn.new(%w[01/14/2013]).for(0)).to eq(Date.new(2013, 1, 14))
32
+ expect(DateColumn.new(%w[13/12/2013 21/11/2013]).for(1))
33
+ .to eq(Date.new(2013, 11, 21))
34
+ expect(DateColumn.new(["2013-11-21"]).for(0)).to eq(Date.new(2013, 11, 21))
35
+ end
41
36
 
42
- describe "#pretty_for" do
43
- it 'should use ledger_date_format' do
44
- expect(Reckon::DateColumn.new(%w[13/02/2013], {ledger_date_format: '%d/%m/%Y'}).pretty_for(0))
45
- .to eq('13/02/2013')
37
+ it "should correctly use endian_precedence" do
38
+ expect(DateColumn.new(%w[01/02/2013 01/14/2013]).for(0))
39
+ .to eq(Date.new(2013, 1, 2))
40
+ expect(DateColumn.new(%w[01/02/2013 14/01/2013]).for(0))
41
+ .to eq(Date.new(2013, 2, 1))
42
+ end
46
43
  end
47
44
 
48
- it 'should default to is' do
49
- expect(Reckon::DateColumn.new(%w[13/12/2013]).pretty_for(0))
50
- .to eq('2013-12-13')
45
+ describe "#pretty_for" do
46
+ it "should use ledger_date_format" do
47
+ expect(
48
+ DateColumn.new(["13/02/2013"],
49
+ { ledger_date_format: "%d/%m/%Y" }).pretty_for(0)
50
+ )
51
+ .to eq("13/02/2013")
52
+ end
53
+
54
+ it "should default to is" do
55
+ expect(DateColumn.new(["13/12/2013"]).pretty_for(0))
56
+ .to eq("2013-12-13")
57
+ end
51
58
  end
52
- end
53
59
 
54
- describe "#likelihood" do
55
- it "should prefer numbers that looks like dates" do
56
- expect(Reckon::DateColumn.likelihood("123456789")).to be < Reckon::DateColumn.likelihood("20160102")
60
+ describe "#likelihood" do
61
+ it "should prefer numbers that looks like dates" do
62
+ expect(DateColumn.likelihood("123456789"))
63
+ .to be < DateColumn.likelihood("20160102")
64
+ end
65
+
66
+ # See https://github.com/cantino/reckon/issues/126
67
+ it "Issue #126 - it shouldn't fail on invalid dates" do
68
+ expect(DateColumn.likelihood("303909302970-07-2023")).to be > 0
69
+ end
57
70
  end
58
71
  end
59
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reckon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Cantino
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-08-25 00:00:00.000000000 Z
13
+ date: 2023-11-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec