textutils 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/textutils/helper/value_helper.rb +2 -116
- data/lib/textutils/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df97568962048f9ec2db3d642b5bd3004e259f76
|
4
|
+
data.tar.gz: 5b59b8cf9cbf492bfde0bc2634e8f9b068f795a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 122a3bb4a655427b8effb7290b4ae9fccdb003e3bb018907f46b38e7eadf29f137a92958b5ac494e2d911c02768c8a083a28e8303ea6e9b13452bc44006f9922
|
7
|
+
data.tar.gz: 031272b63c4e29aa26066c2967f9df341bec2a15a5f04148d398b7a67b055c4dfa0c8c54c71405901e4379fa9a133edea0955a56eadf165a4bea613086368673
|
@@ -4,123 +4,9 @@
|
|
4
4
|
module TextUtils
|
5
5
|
module ValueHelper
|
6
6
|
|
7
|
-
|
8
|
-
## todo/check: add to pair of matchers??
|
9
|
-
# e.g. match_country and match_country!
|
10
|
-
# - match_country will use find_by_key and match_country will use find_by_key! - why? why not?
|
11
|
-
|
12
|
-
def match_country( value )
|
13
|
-
if value =~ /^country:/ # country:
|
14
|
-
country_key = value[8..-1] # cut off country: prefix
|
15
|
-
country = WorldDb::Model::Country.find_by_key!( country_key )
|
16
|
-
yield( country )
|
17
|
-
true # bingo - match found
|
18
|
-
else
|
19
|
-
false # no match found
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def match_supra( value )
|
24
|
-
if value =~ /^supra:/ # supra:
|
25
|
-
country_key = value[6..-1] # cut off supra: prefix
|
26
|
-
country = WorldDb::Model::Country.find_by_key!( country_key )
|
27
|
-
yield( country )
|
28
|
-
true # bingo - match found
|
29
|
-
else
|
30
|
-
false # no match found
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def match_supra_flag( value ) # supranational (country)
|
35
|
-
if value =~ /^supra$/ # supra(national)
|
36
|
-
yield( true )
|
37
|
-
true # bingo - match found
|
38
|
-
else
|
39
|
-
false # no match found
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
def is_region?( value )
|
47
|
-
# assume region code e.g. TX or N
|
48
|
-
#
|
49
|
-
# fix: allow three letter regions too e.g. BRU (brussels)
|
50
|
-
match_result = value =~ /^[A-Z]{1,2}$/
|
51
|
-
# match found if 0,1,2,3 etc or no match if nil
|
52
|
-
# note: return bool e.g. false|true (not 0,1,2,3 etc. and nil)
|
53
|
-
match_result != nil
|
54
|
-
end
|
55
|
-
|
56
|
-
## fix/todo: use match_region_for_country! w/ !!! why? why not?
|
57
|
-
def match_region_for_country( value, country_id ) ## NB: required country_id
|
58
|
-
if value =~ /^region:/ ## region:
|
59
|
-
region_key = value[7..-1] ## cut off region: prefix
|
60
|
-
region = WorldDb::Model::Region.find_by_key_and_country_id!( region_key, country_id )
|
61
|
-
yield( region )
|
62
|
-
true # bingo - match found
|
63
|
-
elsif is_region?( value ) ## assume region code e.g. TX or N
|
64
|
-
region = WorldDb::Model::Region.find_by_key_and_country_id!( value.downcase, country_id )
|
65
|
-
yield( region )
|
66
|
-
true # bingo - match found
|
67
|
-
else
|
68
|
-
false # no match found
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
def match_city( value ) # NB: might be nil (city not found)
|
74
|
-
if value =~ /^city:/ ## city:
|
75
|
-
city_key = value[5..-1] ## cut off city: prefix
|
76
|
-
city = WorldDb::Model::City.find_by_key( city_key )
|
77
|
-
yield( city ) # NB: might be nil (city not found)
|
78
|
-
true # bingo - match found
|
79
|
-
else
|
80
|
-
false # no match found
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
|
-
def match_metro( value )
|
86
|
-
if value =~ /^metro:/ ## metro:
|
87
|
-
city_key = value[6..-1] ## cut off metro: prefix
|
88
|
-
city = WorldDb::Model::City.find_by_key!( city_key ) # NB: parent city/metro required, that is, lookup w/ !
|
89
|
-
yield( city )
|
90
|
-
true # bingo - match found
|
91
|
-
else
|
92
|
-
false # no match found
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
######
|
97
|
-
## fix: move to worlddb?? why why not??
|
98
|
-
def match_metro_flag( value )
|
99
|
-
if value =~ /^metro$/ # metro(politan area)
|
100
|
-
yield( true )
|
101
|
-
true # bingo - match found
|
102
|
-
else
|
103
|
-
false # no match found
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
######
|
108
|
-
## fix: move to worlddb?? why why not??
|
109
|
-
def match_metro_pop( value )
|
110
|
-
if value =~ /^m:/ # m:
|
111
|
-
num = value[2..-1].gsub(/[ _]/, '').to_i # cut off m: prefix; allow space and _ in number
|
112
|
-
yield( num )
|
113
|
-
true # bingo - match found
|
114
|
-
else
|
115
|
-
false # no match found
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
|
120
|
-
|
121
7
|
#####
|
122
|
-
## fix: move to beerdb ??? why? why not??
|
123
|
-
|
8
|
+
## fix: move to beerdb ??? why? why not?? - yes, move to beerdb-models
|
9
|
+
|
124
10
|
def match_brewery( value )
|
125
11
|
if value =~ /^by:/ ## by: -brewed by/brewery
|
126
12
|
brewery_key = value[3..-1] ## cut off by: prefix
|
data/lib/textutils/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: textutils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04
|
11
|
+
date: 2015-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: props
|