dates_from_string 0.9.0 → 0.9.1

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: 420a88c30d1e4c27226cb513d5f9ff99f31fc4a8
4
- data.tar.gz: d1816088a417d53a6b96d334892a0e635a53a6f3
3
+ metadata.gz: 7bc5d7c7e62118b43b4b0bde6f269aec6cce0f96
4
+ data.tar.gz: 5a8e089005f5f2aeaa7f77a6c0f51626eb40b090
5
5
  SHA512:
6
- metadata.gz: c82cb87ad028c5a051a32611fd96925229c4167ec68a20fb726c0b42b46554dd755ba578def4c1ffe347fddfd16e7ae34e3b46c3da7b142dc66c7408ade15433
7
- data.tar.gz: be6219215bae79b00287b7f955e3bf6f2d046bcdbbaa13a62888bb4bc601a19f4e3b6e3e943b6c2a5a7fe23f9909c27816e902d7a0ea524addfc1aef3f85421f
6
+ metadata.gz: 57a72dc0b93afdc6ca1b24f3b480b9ff3f045e3408085364b64d043f72e4df826ea2515909580a386dff7d836e82b7d0edd2e257709cdb19da5704f4d0423434
7
+ data.tar.gz: 44b00fade2e4936e05b2eb490ea37133a903272b1ce77c9d6a23f3eea6c89c10b8757e550ac6b08537cb9dffdf7d3acdc7a793c7a8439721610bc2b213192961
@@ -1,3 +1,3 @@
1
1
  class DatesFromString
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -12,50 +12,60 @@ class DatesFromString
12
12
  end
13
13
 
14
14
  def get_structure(string)
15
- @main_arr = []
16
- data_arr = string.split(" ")
17
- @indexs = []
18
- @first_index = []
19
-
20
- data_arr.each_with_index do |data, index|
21
- value_year = get_year(data)
22
- value_full_date = get_full_date(data)
23
- value_dash = get_dash_data(data)
24
- value_month = get_month_by_list(data)
25
- value_short_month = get_short_month(data)
26
-
27
- value_day = get_day(data)
28
- next_index = index + 1
29
-
30
- if value_year
31
- add_to_structure(:year ,value_year, index, next_index, data_arr)
15
+ unless string.nil? || string.empty?
16
+ @main_arr = []
17
+ data_arr = string.split(" ")
18
+ @indexs = []
19
+ @first_index = []
20
+
21
+ data_arr.each_with_index do |data, index|
22
+ value_year = get_year(data)
23
+ value_full_date = get_full_date(data)
24
+ value_month_year_date = get_month_year_date(data)
25
+ value_dash = get_dash_data(data)
26
+ value_month = get_month_by_list(data)
27
+ value_short_month = get_short_month(data)
28
+
29
+ value_day = get_day(data)
30
+ next_index = index + 1
31
+
32
+ if value_year
33
+ add_to_structure(:year ,value_year, index, next_index, data_arr)
34
+ end
35
+
36
+ if value_full_date
37
+ add_to_structure(:year ,value_full_date[0], index, next_index, data_arr)
38
+ add_to_structure(:month ,value_full_date[1], index, next_index, data_arr)
39
+ add_to_structure(:day ,value_full_date[2], index, next_index, data_arr)
40
+ end
41
+
42
+ if value_month_year_date
43
+ add_to_structure(:year ,value_month_year_date[0], index, next_index, data_arr)
44
+ add_to_structure(:month ,value_month_year_date[1], index, next_index, data_arr)
45
+ end
46
+
47
+ if value_dash
48
+ add_to_structure(:year ,value_dash[0], index, next_index, data_arr, '-')
49
+ add_to_structure(:year ,value_dash[1], index, next_index, data_arr)
50
+ end
51
+
52
+ if value_month
53
+ add_to_structure(:month ,value_month, index, next_index, data_arr)
54
+ end
55
+
56
+ if value_short_month
57
+ add_to_structure(:month ,value_short_month, index, next_index, data_arr)
58
+ end
59
+
60
+ if value_day
61
+ add_to_structure(:day ,value_day, index, next_index, data_arr)
62
+ end
32
63
  end
33
64
 
34
- if value_full_date
35
- add_to_structure(:year ,value_full_date[0], index, next_index, data_arr)
36
- add_to_structure(:month ,value_full_date[1], index, next_index, data_arr)
37
- add_to_structure(:day ,value_full_date[2], index, next_index, data_arr)
38
- end
39
-
40
- if value_dash
41
- add_to_structure(:year ,value_dash[0], index, next_index, data_arr, '-')
42
- add_to_structure(:year ,value_dash[1], index, next_index, data_arr)
43
- end
44
-
45
- if value_month
46
- add_to_structure(:month ,value_month, index, next_index, data_arr)
47
- end
48
-
49
- if value_short_month
50
- add_to_structure(:month ,value_short_month, index, next_index, data_arr)
51
- end
52
-
53
- if value_day
54
- add_to_structure(:day ,value_day, index, next_index, data_arr)
55
- end
65
+ return @main_arr
66
+ else
67
+ nil
56
68
  end
57
-
58
- return @main_arr
59
69
  end
60
70
 
61
71
  def get_year(string)
@@ -90,6 +100,16 @@ class DatesFromString
90
100
  end
91
101
  end
92
102
 
103
+ def get_month_year_date(string)
104
+ if (result = string.match(/^\d{2}\.\d{4}$/))
105
+ result.to_s.split(".").reverse
106
+ elsif (result = string.match(/^\d{4}\.\d{2}$/))
107
+ result.to_s.split(".")
108
+ else
109
+ nil
110
+ end
111
+ end
112
+
93
113
  def get_day(string)
94
114
  if string =~ (/^\d{2}$/)
95
115
  string
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dates_from_string
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Chechaev