dates_from_string 0.9.0 → 0.9.1
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/lib/dates_from_string/version.rb +1 -1
- data/lib/dates_from_string.rb +61 -41
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bc5d7c7e62118b43b4b0bde6f269aec6cce0f96
|
4
|
+
data.tar.gz: 5a8e089005f5f2aeaa7f77a6c0f51626eb40b090
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57a72dc0b93afdc6ca1b24f3b480b9ff3f045e3408085364b64d043f72e4df826ea2515909580a386dff7d836e82b7d0edd2e257709cdb19da5704f4d0423434
|
7
|
+
data.tar.gz: 44b00fade2e4936e05b2eb490ea37133a903272b1ce77c9d6a23f3eea6c89c10b8757e550ac6b08537cb9dffdf7d3acdc7a793c7a8439721610bc2b213192961
|
data/lib/dates_from_string.rb
CHANGED
@@ -12,50 +12,60 @@ class DatesFromString
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def get_structure(string)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
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
|