dates_from_string 0.9.5 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dates_from_string.rb +14 -0
- data/lib/dates_from_string/version.rb +1 -1
- data/lib/parsing_structure.rb +63 -14
- 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: 49288f123d0486bd93b3d756c9275fc9c9f4f690
|
4
|
+
data.tar.gz: 9e50a1e44fbed5e9dfba1b8d5655b27590b224bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b587c7d192b80b5fcccad9e9fd23d5b5c49374d4164d0dc25a10a3392d40142dbd68c1155e42b61cedfb78836b456dec11f4904eeded97d3fb7b9cb63b969deb
|
7
|
+
data.tar.gz: a48c80c4b14be0d710f90a66810d08f598eb3cc5597d22b787957726ffdedecf0305d6b6e8edf042fa81b328ea07feb507784356c07a13bf04ea2f719bf1f56a
|
data/lib/dates_from_string.rb
CHANGED
@@ -26,6 +26,7 @@ class DatesFromString
|
|
26
26
|
value_dash = get_dash_data(data)
|
27
27
|
value_month = get_month_by_list(data)
|
28
28
|
value_short_month = get_short_month(data)
|
29
|
+
value_time = get_time(data)
|
29
30
|
|
30
31
|
value_day = get_day(data)
|
31
32
|
next_index = index + 1
|
@@ -64,6 +65,11 @@ class DatesFromString
|
|
64
65
|
if value_day
|
65
66
|
add_to_structure(:day ,value_day, index, next_index, data_arr)
|
66
67
|
end
|
68
|
+
|
69
|
+
if value_time
|
70
|
+
add_to_structure(:time ,value_time, index, next_index, data_arr)
|
71
|
+
end
|
72
|
+
|
67
73
|
end
|
68
74
|
|
69
75
|
return @main_arr
|
@@ -72,6 +78,14 @@ class DatesFromString
|
|
72
78
|
end
|
73
79
|
end
|
74
80
|
|
81
|
+
def get_time(string)
|
82
|
+
if (result = string.match(/\d{2}:\d{2}:\d{2}/))
|
83
|
+
result.to_s
|
84
|
+
else
|
85
|
+
nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
75
89
|
def get_year(string)
|
76
90
|
if string =~ /^\d{4}$/
|
77
91
|
string
|
data/lib/parsing_structure.rb
CHANGED
@@ -4,34 +4,83 @@ class ParsingStructure
|
|
4
4
|
|
5
5
|
def initialize(structure)
|
6
6
|
@structure = structure
|
7
|
+
|
8
|
+
@array_of_full_data = []
|
7
9
|
end
|
8
10
|
|
9
11
|
def start
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
if @structure
|
13
|
+
if (@structure.select {|father| father[:type] == :time }).any?
|
14
|
+
get_year_month_day_time
|
15
|
+
else
|
16
|
+
get_year_month_day
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
return @array_of_full_data
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_year_month_day_time
|
24
|
+
set_year_month_day_time
|
14
25
|
|
15
26
|
if @structure
|
16
27
|
@structure.each do |item|
|
17
|
-
if item[:type] == :year
|
18
|
-
year = item[:value]
|
28
|
+
if item[:type] == :year
|
29
|
+
@year = item[:value]
|
19
30
|
end
|
20
31
|
|
21
|
-
if item[:type] == :month
|
22
|
-
month = item[:value]
|
32
|
+
if item[:type] == :month
|
33
|
+
@month = item[:value]
|
23
34
|
end
|
24
35
|
|
25
|
-
if item[:type] == :day
|
26
|
-
day = item[:value]
|
36
|
+
if item[:type] == :day
|
37
|
+
@day = item[:value]
|
27
38
|
end
|
28
39
|
|
29
|
-
if
|
30
|
-
|
40
|
+
if item[:type] == :time
|
41
|
+
@time = item[:value]
|
42
|
+
end
|
43
|
+
|
44
|
+
if @year && @month && @day && @time
|
45
|
+
@array_of_full_data << [[@year,@month,@day].join("-"), @time].join(" ")
|
31
46
|
end
|
32
47
|
end
|
33
48
|
end
|
34
49
|
|
35
|
-
array_of_full_data
|
50
|
+
@array_of_full_data
|
36
51
|
end
|
37
|
-
|
52
|
+
|
53
|
+
def get_year_month_day
|
54
|
+
set_year_month_day_time
|
55
|
+
|
56
|
+
if @structure
|
57
|
+
@structure.each do |item|
|
58
|
+
if item[:type] == :year
|
59
|
+
@year = item[:value]
|
60
|
+
end
|
61
|
+
|
62
|
+
if item[:type] == :month
|
63
|
+
@month = item[:value]
|
64
|
+
end
|
65
|
+
|
66
|
+
if item[:type] == :day
|
67
|
+
@day = item[:value]
|
68
|
+
end
|
69
|
+
|
70
|
+
if @year && @month && @day
|
71
|
+
@array_of_full_data << [@year,@month,@day].join("-")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
@array_of_full_data
|
77
|
+
end
|
78
|
+
|
79
|
+
def set_year_month_day_time
|
80
|
+
@year = nil
|
81
|
+
@month = nil
|
82
|
+
@day = nil
|
83
|
+
@time = nil
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
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.9.
|
4
|
+
version: 0.9.6
|
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-09-
|
11
|
+
date: 2015-09-07 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: :development
|
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: Flexible solution for finding all formats of dates in text
|
@@ -59,9 +59,9 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
-
|
63
|
-
-
|
64
|
-
-
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- .travis.yml
|
65
65
|
- CODE_OF_CONDUCT.md
|
66
66
|
- Gemfile
|
67
67
|
- LICENSE.txt
|
@@ -83,17 +83,17 @@ require_paths:
|
|
83
83
|
- lib
|
84
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- -
|
86
|
+
- - '>='
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
90
|
requirements:
|
91
|
-
- -
|
91
|
+
- - '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.0.14
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: Flexible solution for finding all formats of dates in text
|