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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98fe2e3e849f5760bd532ad4c48976cf4164859f
4
- data.tar.gz: e716c189b4f6612b5ff9b858c1fbe636d8c07c75
3
+ metadata.gz: 49288f123d0486bd93b3d756c9275fc9c9f4f690
4
+ data.tar.gz: 9e50a1e44fbed5e9dfba1b8d5655b27590b224bf
5
5
  SHA512:
6
- metadata.gz: 974f4f2f5e0d61b4e4cdb499fcfdc0b8c075f09e7dc36d06f15c7883f90eaca3650746f867088886c67e76029bdc81a9cca78ec6cbdb61dc7e45b08c2b40128e
7
- data.tar.gz: daeaba06a1e1811f7448988d3e8a64ee81871183284a825b1add5e4c2f75baf702b00f4718a431f29e4ca22e253f12d4a0f7d34e76da5648a61d54a752b05620
6
+ metadata.gz: b587c7d192b80b5fcccad9e9fd23d5b5c49374d4164d0dc25a10a3392d40142dbd68c1155e42b61cedfb78836b456dec11f4904eeded97d3fb7b9cb63b969deb
7
+ data.tar.gz: a48c80c4b14be0d710f90a66810d08f598eb3cc5597d22b787957726ffdedecf0305d6b6e8edf042fa81b328ea07feb507784356c07a13bf04ea2f719bf1f56a
@@ -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
@@ -1,3 +1,3 @@
1
1
  class DatesFromString
2
- VERSION = "0.9.5"
2
+ VERSION = "0.9.6"
3
3
  end
@@ -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
- array_of_full_data = []
11
- year = nil
12
- month = nil
13
- day = nil
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 && item[:distance] == 0
18
- year = item[:value]
28
+ if item[:type] == :year
29
+ @year = item[:value]
19
30
  end
20
31
 
21
- if item[:type] == :month && item[:distance] == 0
22
- month = item[:value]
32
+ if item[:type] == :month
33
+ @month = item[:value]
23
34
  end
24
35
 
25
- if item[:type] == :day && item[:distance] == 0
26
- day = item[:value]
36
+ if item[:type] == :day
37
+ @day = item[:value]
27
38
  end
28
39
 
29
- if year && month && day
30
- array_of_full_data << [year,month,day].join("-")
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
- end
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.5
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-02 00:00:00.000000000 Z
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
- - ".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.2.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