dates_from_string 0.3.0 → 0.4.0
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.
- checksums.yaml +4 -4
- data/README.md +69 -3
- data/lib/dates_from_string.rb +35 -0
- data/lib/dates_from_string/version.rb +1 -1
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3a11b4fa95109a8912aeafc2f26059329ab202a
|
4
|
+
data.tar.gz: 82965858f5db7e757f59c052d9efdaa602b38bcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c6150df8d07c0f8fae1e3c88a9dd2ff1bafeee14c777b865cf81c4263860cbe9014bc0420d5c3d79e3bf0c8abe249effae70febda78c872207d8389bb71d8d8
|
7
|
+
data.tar.gz: 5c22bb5e72c83bb798e5f585c1b17b1971c131c98889fb4c56aec5448f9c117d9ba00bb35500ea615746dd469bc71abbe5b8ef85b7003c19e5eb98ad536c7ad0
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# DatesFromString
|
2
2
|
|
3
|
-
|
3
|
+
Flexible solution for finding dates in text. After parsing text gem return flexible structure of dates, also you can get array of dates.
|
4
4
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
@@ -22,7 +21,74 @@ Or install it yourself as:
|
|
22
21
|
|
23
22
|
## Usage
|
24
23
|
|
25
|
-
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
text = "1988-1990 and 2000 and one more date 28.04.2015" # parsing text
|
27
|
+
key_words = ['between','-'] # you can define special separator
|
28
|
+
dates_from_string = DatesFromString.new(key_words) # define DatesFromString object
|
29
|
+
dates_from_string.get_structure(text) # parsing text
|
30
|
+
|
31
|
+
#=> returns
|
32
|
+
# [{:type=>:year, :value=>"1988", :distance=>0, :key_words=>["-"]},
|
33
|
+
# {:type=>:year, :value=>"1990", :distance=>2, :key_words=>[]},
|
34
|
+
# {:type=>:year, :value=>"2000", :distance=>5, :key_words=>[]},
|
35
|
+
# {:type=>:year, :value=>"2015", :distance=>0, :key_words=>[]},
|
36
|
+
# {:type=>:month, :value=>"04", :distance=>0, :key_words=>[]},
|
37
|
+
# {:type=>:day, :value=>"28", :distance=>0, :key_words=>[]}]
|
38
|
+
|
39
|
+
:type # type of date year, month or day
|
40
|
+
:value # value of date
|
41
|
+
:distance # distance for next date type
|
42
|
+
:key_words # special words, symbols that separate dates
|
43
|
+
```
|
44
|
+
|
45
|
+
Examples:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
input = '1988 between 1990'
|
49
|
+
key_words = ['between']
|
50
|
+
dates_from_string = DatesFromString.new(key_words)
|
51
|
+
dates_from_string.get_structure(input)
|
52
|
+
|
53
|
+
#=> return
|
54
|
+
# [{:type=>:year, :value=>"1988", :distance=>2, :key_words=>["between"]},
|
55
|
+
# {:type=>:year, :value=>"1990", :distance=>0, :key_words=>[]}]
|
56
|
+
|
57
|
+
input = '2013/07/09 one date and he born in 1990'
|
58
|
+
dates_from_string.get_structure(input)
|
59
|
+
|
60
|
+
#=> return
|
61
|
+
# [{:type=>:year, :value=>"2013", :distance=>0, :key_words=>[]},
|
62
|
+
# {:type=>:month, :value=>"07", :distance=>0, :key_words=>[]},
|
63
|
+
# {:type=>:day, :value=>"09", :distance=>7, :key_words=>[]},
|
64
|
+
# {:type=>:year, :value=>"1990", :distance=>0, :key_words=>[]}]
|
65
|
+
|
66
|
+
input = '1990 1988 year 2013 bla bla bla 2015 a b c d i f g qwe 2016'
|
67
|
+
dates_from_string.get_structure(input)
|
68
|
+
|
69
|
+
#=> return
|
70
|
+
# [{:type=>:year, :value=>"1990", :distance=>1, :key_words=>[]},
|
71
|
+
# {:type=>:year, :value=>"1988", :distance=>2, :key_words=>[]},
|
72
|
+
# {:type=>:year, :value=>"2013", :distance=>4, :key_words=>[]},
|
73
|
+
# {:type=>:year, :value=>"2015", :distance=>9, :key_words=>[]},
|
74
|
+
# {:type=>:year, :value=>"2016", :distance=>0, :key_words=>[]}]
|
75
|
+
|
76
|
+
input = 'August 1961'
|
77
|
+
dates_from_string.get_structure(input)
|
78
|
+
|
79
|
+
#=> return
|
80
|
+
# [{:type=>:month, :value=>"08", :distance=>1, :key_words=>[]},
|
81
|
+
# {:type=>:year, :value=>"1961", :distance=>0, :key_words=>[]}]
|
82
|
+
|
83
|
+
input = '10 April 1948'
|
84
|
+
dates_from_string.get_structure(input)
|
85
|
+
|
86
|
+
#=> return
|
87
|
+
# [{:type=>:day, :value=>"10", :distance=>1, :key_words=>[]},
|
88
|
+
# {:type=>:month, :value=>"04", :distance=>1, :key_words=>[]},
|
89
|
+
# {:type=>:year, :value=>"1948", :distance=>0, :key_words=>[]}]
|
90
|
+
#
|
91
|
+
```
|
26
92
|
|
27
93
|
## Development
|
28
94
|
|
data/lib/dates_from_string.rb
CHANGED
@@ -21,6 +21,9 @@ class DatesFromString
|
|
21
21
|
value_full_date = get_full_date(data)
|
22
22
|
value_dash = get_dash_data(data)
|
23
23
|
value_month = get_month_by_list(data)
|
24
|
+
value_short_month = get_short_month(data)
|
25
|
+
|
26
|
+
value_day = get_day(data)
|
24
27
|
next_index = index + 1
|
25
28
|
|
26
29
|
if value_year
|
@@ -41,6 +44,14 @@ class DatesFromString
|
|
41
44
|
if value_month
|
42
45
|
add_to_structure(:month ,value_month, index, next_index, data_arr)
|
43
46
|
end
|
47
|
+
|
48
|
+
if value_short_month
|
49
|
+
add_to_structure(:month ,value_short_month, index, next_index, data_arr)
|
50
|
+
end
|
51
|
+
|
52
|
+
if value_day
|
53
|
+
add_to_structure(:day ,value_day, index, next_index, data_arr)
|
54
|
+
end
|
44
55
|
end
|
45
56
|
|
46
57
|
return @main_arr
|
@@ -67,11 +78,22 @@ class DatesFromString
|
|
67
78
|
string.split("/")
|
68
79
|
elsif string =~ (/\d{2}\/\d{2}\/\d{4}/)
|
69
80
|
string.split("/").reverse
|
81
|
+
# elsif string =~(/\d{2}\s{1}(Jan|Feb|Mar|Apr|May|Jun|Jul|Apr|Sep|Oct|Nov|Dec)\s{1}\d{4}/)
|
82
|
+
# string.to_date.to_s.split("-")
|
83
|
+
else
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_day(string)
|
89
|
+
if string =~ (/^\d{2}$/)
|
90
|
+
string
|
70
91
|
else
|
71
92
|
nil
|
72
93
|
end
|
73
94
|
end
|
74
95
|
|
96
|
+
|
75
97
|
def get_dash_data(string)
|
76
98
|
if string =~ (/\d{4}-\d{4}/)
|
77
99
|
string.split("-")
|
@@ -83,11 +105,24 @@ class DatesFromString
|
|
83
105
|
def get_month_by_list(string)
|
84
106
|
month = ['January','February','March','April','May','June','July','August','September','October','November','December']
|
85
107
|
index = month.index(string)
|
108
|
+
|
86
109
|
if index
|
87
110
|
sprintf('%02d',(index+1))
|
88
111
|
else
|
89
112
|
nil
|
90
113
|
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
def get_short_month(string)
|
118
|
+
short_month = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Apr','Sep','Oct','Nov','Dec']
|
119
|
+
short_index = short_month.index(string)
|
120
|
+
|
121
|
+
if short_index
|
122
|
+
sprintf('%02d',(short_index+1))
|
123
|
+
else
|
124
|
+
nil
|
125
|
+
end
|
91
126
|
end
|
92
127
|
|
93
128
|
def add_to_structure (type ,value, index, next_index, data_arr, key_word = nil)
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dates_from_string
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Chechaev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.9'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.9'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: pry-rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: Find dates in string and return array of dates
|
@@ -59,9 +59,9 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- .gitignore
|
63
|
-
- .rspec
|
64
|
-
- .travis.yml
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
65
|
- CODE_OF_CONDUCT.md
|
66
66
|
- Gemfile
|
67
67
|
- LICENSE.txt
|
@@ -82,17 +82,17 @@ require_paths:
|
|
82
82
|
- lib
|
83
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
84
|
requirements:
|
85
|
-
- -
|
85
|
+
- - ">="
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: '0'
|
88
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
89
|
requirements:
|
90
|
-
- -
|
90
|
+
- - ">="
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.4.6
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: Flexible solution for finding all formats of dates in text
|