dates_from_string 0.9.6 → 0.9.7

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
  SHA1:
3
- metadata.gz: 49288f123d0486bd93b3d756c9275fc9c9f4f690
4
- data.tar.gz: 9e50a1e44fbed5e9dfba1b8d5655b27590b224bf
3
+ metadata.gz: 83bfa65e4f0d7901c31904095176ea3a38f159a5
4
+ data.tar.gz: ffa288a432eff1afb3494466dc9153c3f3c7869f
5
5
  SHA512:
6
- metadata.gz: b587c7d192b80b5fcccad9e9fd23d5b5c49374d4164d0dc25a10a3392d40142dbd68c1155e42b61cedfb78836b456dec11f4904eeded97d3fb7b9cb63b969deb
7
- data.tar.gz: a48c80c4b14be0d710f90a66810d08f598eb3cc5597d22b787957726ffdedecf0305d6b6e8edf042fa81b328ea07feb507784356c07a13bf04ea2f719bf1f56a
6
+ metadata.gz: 741dc8c86493e3c006a378e2b9e1af61bc2574427199111d039a1e01ee75a06897c750bd79d44728147b59d8d1c4f1783286de49f1341a24764cdaac0470d54a
7
+ data.tar.gz: d4619ed1d86312786684240cabcd0b8ba8bc7d0cc680c8aad69b6b6ea808b64ec0a6f95bd4d6db472464c3d617784ffb93c4c612163de0cfe3b5703ac0d5da0b
@@ -1,3 +1,3 @@
1
1
  class DatesFromString
2
- VERSION = "0.9.6"
2
+ VERSION = "0.9.7"
3
3
  end
@@ -3,6 +3,34 @@ require "parsing_structure"
3
3
 
4
4
  class DatesFromString
5
5
 
6
+
7
+ PATTERNS = {
8
+ [
9
+ /\d{4}-\d{2}-\d{2}/,
10
+ /\d{4}-\d{1}-\d{2}/,
11
+ /\d{4}-\d{1}-\d{1}/,
12
+ /\d{4}-\d{2}-\d{1}/,
13
+ ] => -> string { string.to_s.split("-") },
14
+ [
15
+ /\d{2}-\d{2}-\d{4}/,
16
+ /\d{2}-\d{1}-\d{4}/,
17
+ /\d{1}-\d{1}-\d{4}/,
18
+ /\d{1}-\d{2}-\d{4}/,
19
+ ] => -> string { string.to_s.split("-").reverse },
20
+ [
21
+ /\d{4}\.\d{2}\.\d{2}/,
22
+ ] => -> string { string.to_s.split(".") },
23
+ [
24
+ /\d{2}\.\d{2}\.\d{4}/,
25
+ ] => -> string { string.to_s.split(".").reverse },
26
+ [
27
+ /\d{4}\/\d{2}\/\d{2}/,
28
+ ] => -> string { string.to_s.split("/") },
29
+ [
30
+ /\d{2}\/\d{2}\/\d{4}/,
31
+ ] => -> string { string.to_s.split("/").reverse },
32
+ }
33
+
6
34
  def initialize(key_words = [])
7
35
  @key_words = key_words
8
36
  end
@@ -12,12 +40,17 @@ class DatesFromString
12
40
  parsing_structure.start
13
41
  end
14
42
 
43
+ def get_clear_text
44
+ @clear_text.strip
45
+ end
46
+
15
47
  def get_structure(string)
16
48
  unless string.nil? || string.empty?
17
49
  @main_arr = []
18
50
  data_arr = string.split(" ")
19
51
  @indexs = []
20
52
  @first_index = []
53
+ @clear_text = string.clone
21
54
 
22
55
  data_arr.each_with_index do |data, index|
23
56
  value_year = get_year(data)
@@ -80,6 +113,10 @@ class DatesFromString
80
113
 
81
114
  def get_time(string)
82
115
  if (result = string.match(/\d{2}:\d{2}:\d{2}/))
116
+ @clear_text.slice!(result.to_s)
117
+ result.to_s
118
+ elsif (result = string.match(/\d{2}:\d{2}/))
119
+ @clear_text.slice!(result.to_s)
83
120
  result.to_s
84
121
  else
85
122
  nil
@@ -99,35 +136,18 @@ class DatesFromString
99
136
  end
100
137
 
101
138
  def get_full_date(string)
102
- if (result = string.match(/\d{4}-\d{2}-\d{2}/))
103
- result.to_s.split("-")
104
- elsif (result = string.match(/\d{2}-\d{2}-\d{4}/))
105
- result.to_s.split("-").reverse
106
- elsif (result = string.match(/\d{4}-\d{1}-\d{2}/))
107
- result.to_s.split("-")
108
- elsif (result = string.match(/\d{2}-\d{1}-\d{4}/))
109
- result.to_s.split("-").reverse
110
- elsif (result = string.match(/\d{4}-\d{1}-\d{1}/))
111
- result.to_s.split("-")
112
- elsif (result = string.match(/\d{1}-\d{1}-\d{4}/))
113
- result.to_s.split("-").reverse
114
- elsif (result = string.match(/\d{4}-\d{2}-\d{1}/))
115
- result.to_s.split("-")
116
- elsif (result = string.match(/\d{1}-\d{2}-\d{4}/))
117
- result.to_s.split("-").reverse
118
- elsif (result = string.match(/\d{4}\.\d{2}\.\d{2}/))
119
- result.to_s.split(".")
120
- elsif (result = string.match(/\d{2}\.\d{2}\.\d{4}/))
121
- result.to_s.split(".").reverse
122
- elsif (result = string.match(/\d{4}\/\d{2}\/\d{2}/))
123
- result.to_s.split("/")
124
- elsif (result = string.match(/\d{2}\/\d{2}\/\d{4}/))
125
- result.to_s.split("/").reverse
126
- # elsif string =~(/\d{2}\s{1}(Jan|Feb|Mar|Apr|May|Jun|Jul|Apr|Sep|Oct|Nov|Dec)\s{1}\d{4}/)
127
- # string.to_date.to_s.split("-")
128
- else
129
- nil
139
+
140
+ PATTERNS.keys.each do |patterns|
141
+ patterns.each do |pattern|
142
+ if (result = string.match(pattern))
143
+ @clear_text.slice!(result.to_s)
144
+ return PATTERNS[patterns].call result
145
+ end
146
+ end
130
147
  end
148
+
149
+ return nil
150
+
131
151
  end
132
152
 
133
153
  def get_month_year_date(string)
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.6
4
+ version: 0.9.7
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-07 00:00:00.000000000 Z
11
+ date: 2015-09-08 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
- - .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
@@ -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.0.14
96
+ rubygems_version: 2.4.6
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: Flexible solution for finding all formats of dates in text