textutils 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,9 +5,24 @@ module TextUtils
5
5
  module ValueHelper
6
6
 
7
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
+
8
12
  def match_country( value )
9
- if value =~ /^country:/ ## country:
10
- country_key = value[8..-1] ## cut off country: prefix
13
+ if value =~ /^country:/ # country:
14
+ country_key = value[8..-1] # cut off country: prefix
15
+ country = 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
11
26
  country = Country.find_by_key!( country_key )
12
27
  yield( country )
13
28
  true # bingo - match found
@@ -16,6 +31,17 @@ module TextUtils
16
31
  end
17
32
  end
18
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
+
19
45
 
20
46
  def is_region?( value )
21
47
  # assume region code e.g. TX or N
@@ -39,7 +65,7 @@ module TextUtils
39
65
  end
40
66
 
41
67
 
42
- def match_city( value )
68
+ def match_city( value ) # NB: might be nil (city not found)
43
69
  if value =~ /^city:/ ## city:
44
70
  city_key = value[5..-1] ## cut off city: prefix
45
71
  city = City.find_by_key( city_key )
@@ -51,6 +77,39 @@ module TextUtils
51
77
  end
52
78
 
53
79
 
80
+ def match_metro( value )
81
+ if value =~ /^metro:/ ## metro:
82
+ city_key = value[6..-1] ## cut off metro: prefix
83
+ city = City.find_by_key!( city_key ) # NB: parent city/metro required, that is, lookup w/ !
84
+ yield( city )
85
+ true # bingo - match found
86
+ else
87
+ false # no match found
88
+ end
89
+ end
90
+
91
+ def match_metro_flag( value )
92
+ if value =~ /^metro$/ # metro(politan area)
93
+ yield( true )
94
+ true # bingo - match found
95
+ else
96
+ false # no match found
97
+ end
98
+ end
99
+
100
+ def match_metro_pop( value )
101
+ if value =~ /^m:/ # m:
102
+ num = value[2..-1].gsub(/[ _]/, '').to_i # cut off m: prefix; allow space and _ in number
103
+ yield( num )
104
+ true # bingo - match found
105
+ else
106
+ false # no match found
107
+ end
108
+ end
109
+
110
+
111
+
112
+
54
113
  def match_brewery( value )
55
114
  if value =~ /^by:/ ## by: -brewed by/brewery
56
115
  brewery_key = value[3..-1] ## cut off by: prefix
@@ -78,6 +137,31 @@ module TextUtils
78
137
  end
79
138
 
80
139
 
140
+ def match_km_squared( value )
141
+ ## allow numbers like 453 km² or 45_000 km2
142
+ if value =~ /^([0-9][0-9 _]+[0-9]|[0-9]{1,2})(?:\s*(?:km2|km²)\s*)$/
143
+ num = value.gsub( 'km2', '').gsub( 'km²', '' ).gsub(/[ _]/, '').to_i
144
+ yield( num )
145
+ true # bingo - match found
146
+ else
147
+ false # no match found
148
+ end
149
+ end
150
+
151
+ def match_number( value )
152
+ ## numeric (nb: can use any _ or spaces inside digits e.g. 1_000_000 or 1 000 000)
153
+ if value =~ /^([0-9][0-9 _]+[0-9])|([0-9]{1,2})$/
154
+ num = value.gsub(/[ _]/, '').to_i
155
+ yield( num )
156
+ true # bingo - match found
157
+ else
158
+ false # no match found
159
+ end
160
+ end
161
+
162
+
163
+
164
+
81
165
  def is_website?( value )
82
166
  # check for url/internet address e.g. www.ottakringer.at
83
167
  # - must start w/ www. or
@@ -1,6 +1,6 @@
1
1
 
2
2
  module TextUtils
3
3
 
4
- VERSION = '0.6.0'
4
+ VERSION = '0.6.1'
5
5
 
6
6
  end # module TextUtils
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: textutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: logutils
16
- requirement: &84354180 !ruby/object:Gem::Requirement
16
+ requirement: &79931880 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.5'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *84354180
24
+ version_requirements: *79931880
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rdoc
27
- requirement: &84353960 !ruby/object:Gem::Requirement
27
+ requirement: &79931660 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.10'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *84353960
35
+ version_requirements: *79931660
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: hoe
38
- requirement: &84353740 !ruby/object:Gem::Requirement
38
+ requirement: &79931440 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '3.3'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *84353740
46
+ version_requirements: *79931440
47
47
  description: textutils - Text Filters, Helpers, Readers and More
48
48
  email: webslideshow@googlegroups.com
49
49
  executables: []