dates_from_string 0.5.0 → 0.6.0
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/README.md +15 -4
- data/lib/dates_from_string.rb +4 -0
- data/lib/dates_from_string/version.rb +1 -1
- 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: a7f3aad632d0a54f6bfb007d875bdca1da734c07
|
4
|
+
data.tar.gz: 9db1c2e76db53abd438ffec8824f33640e0112cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 168000c875ef7203c827689251c722a84c96859bec290086849e05715abd3d16801e269047f05b9f4ee6460322190216c4c392c8d0716a60a510cd6ffed94353
|
7
|
+
data.tar.gz: cd4aba31a3bee5a47f2bf820521c3e5395da30ab1f7184a71a55174970e0b9fb18538db08aaa4e128e66c0b931aada0e37e76c967d71ae5c830fbd9306104bec
|
data/README.md
CHANGED
@@ -90,11 +90,22 @@ dates_from_string.get_structure(input)
|
|
90
90
|
#
|
91
91
|
|
92
92
|
input = 'circa 1960 and full date 07 Jun 1941'
|
93
|
+
dates_from_string.get_structure(input)
|
94
|
+
|
95
|
+
#=> return
|
96
|
+
# [{:type=>:year, :value=>"1960", :distance=>4, :key_words=>[]},
|
97
|
+
# {:type=>:day, :value=>"07", :distance=>1, :key_words=>[]},
|
98
|
+
# {:type=>:month, :value=>"06", :distance=>1, :key_words=>[]},
|
99
|
+
# {:type=>:year, :value=>"1941", :distance=>0, :key_words=>[]}]
|
100
|
+
|
101
|
+
obj = DatesFromString.new(['and'])
|
102
|
+
input = 'between 1960 and 1965'
|
103
|
+
obj.get_structure(input)
|
104
|
+
|
93
105
|
#=> return
|
94
|
-
#[{:type=>:year, :value=>"1960", :distance=>
|
95
|
-
#{:type=>:
|
96
|
-
|
97
|
-
#{:type=>:year, :value=>"1941", :distance=>0, :key_words=>[]}]
|
106
|
+
# [{:type=>:year, :value=>"1960", :distance=>2, :key_words=>['and']},
|
107
|
+
# {:type=>:year, :value=>"1965", :distance=>0, :key_words=>[]},]
|
108
|
+
|
98
109
|
```
|
99
110
|
|
100
111
|
## Development
|
data/lib/dates_from_string.rb
CHANGED
@@ -15,6 +15,7 @@ class DatesFromString
|
|
15
15
|
@main_arr = []
|
16
16
|
data_arr = string.split(" ")
|
17
17
|
@indexs = []
|
18
|
+
@first_index = []
|
18
19
|
|
19
20
|
data_arr.each_with_index do |data, index|
|
20
21
|
value_year = get_year(data)
|
@@ -128,6 +129,7 @@ class DatesFromString
|
|
128
129
|
def add_to_structure (type ,value, index, next_index, data_arr, key_word = nil)
|
129
130
|
set_structura
|
130
131
|
if value
|
132
|
+
@first_index << index
|
131
133
|
@structura[:type] = type
|
132
134
|
@structura[:value] = value
|
133
135
|
end
|
@@ -155,6 +157,8 @@ class DatesFromString
|
|
155
157
|
@indexs << index
|
156
158
|
if @indexs.count > 1
|
157
159
|
result = (index - @indexs[-2])
|
160
|
+
elsif @first_index[0] < index
|
161
|
+
result = (index - @first_index[0])
|
158
162
|
else
|
159
163
|
result = index
|
160
164
|
end
|