textutils 0.5.12 → 0.5.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,6 +24,30 @@ module TextUtils
24
24
 
25
25
  new_address_line
26
26
  end
27
+
28
+
29
+ # todo/fix: add _in_adr or _in_addr to name - why? why not?
30
+
31
+ def find_city_for_country( country_key, address )
32
+
33
+ return nil if address.blank? # do NOT process nil or empty address lines; sorry
34
+
35
+ lines = address.split( '//' )
36
+
37
+ if country_key == 'at' || country_key == 'de'
38
+ # first line strip numbers (assuming zip code) and whitespace
39
+ line1 = lines[0]
40
+ line1 = line1.gsub( /\b[0-9]+\b/, '' ) # use word boundries (why? why not?)
41
+ line1 = line1.strip
42
+
43
+ return nil if line1.blank? # nothing left sorry; better return nil
44
+
45
+ line1 # assume its the city
46
+ else
47
+ nil # unsupported country/address schema for now; sorry
48
+ end
49
+ end
50
+
27
51
 
28
52
  end # module AddressHelper
29
53
  end # module TextUtils
@@ -4,6 +4,9 @@
4
4
  module TextUtils
5
5
  module TitleHelper
6
6
 
7
+
8
+
9
+
7
10
  def strip_translations( title )
8
11
  # remove optional english translation in square brackets ([])
9
12
  # e.g. Wien [Vienna] => Wien
@@ -34,5 +34,26 @@ module TextUtils
34
34
  end
35
35
 
36
36
 
37
+ def find_grade( text ) # NB: returns ary [grade,text] / two values
38
+ grade = 4 # defaults to grade 4 e.g *** => 1, ** => 2, * => 3, -/- => 4
39
+
40
+ text = text.sub( /\s+(\*{1,3})\s*$/ ) do |_| # NB: stars must end field/value
41
+ if $1 == '***'
42
+ grade = 1
43
+ elsif $1 == '**'
44
+ grade = 2
45
+ elsif $1 == '*'
46
+ grade = 3
47
+ else
48
+ # unknown grade; not possible, is'it?
49
+ end
50
+ '' # remove * from title if found
51
+ end
52
+
53
+ [grade,text]
54
+ end
55
+
56
+
57
+
37
58
  end # module ValueHelper
38
59
  end # module TextUtils
@@ -5,6 +5,9 @@
5
5
  class ValuesReader
6
6
 
7
7
  include LogUtils::Logging
8
+
9
+ include TextUtils::ValueHelper # e.g. includes find_grade()
10
+
8
11
 
9
12
  def initialize( path, more_values={} )
10
13
  @path = path
@@ -68,7 +71,7 @@ class ValuesReader
68
71
  if line =~ /^[a-z][a-z0-9.]*[a-z0-9]:/
69
72
  # NB: every additional line is one value e.g. city:wien, etc.
70
73
  # allows you to use any chars
71
- logger.debug " multi-line record - add key-value >#{line}<"
74
+ logger.debug " multi-line record - add key-value »#{line}«"
72
75
 
73
76
  more_cols.unshift( line.dup ) # add value upfront to array (first value); lets us keep (optional) tags as last entry; fix!! see valuereaderEx v2
74
77
  next
@@ -85,18 +88,17 @@ class ValuesReader
85
88
 
86
89
 
87
90
  ### guard escaped commas (e.g. \,)
88
- line = line.gsub( '\,', '@commma@' )
91
+ line = line.gsub( '\,', '' ) # use black club suit/=shamrock char for escaped separator
89
92
 
90
93
  ## use generic separator (allow us to configure separator)
91
- line = line.gsub( ',', '@sep@')
94
+ line = line.gsub( ',', '') # use black diamond suit for separator
92
95
 
93
96
  ## restore escaped commas (before split)
94
- line = line.gsub( '@commma@', ',' )
95
-
97
+ line = line.gsub( '', ',' )
96
98
 
97
- logger.debug "line: >>#{line}<<"
99
+ logger.debug "line: »#{line}«"
98
100
 
99
- values = line.split( '@sep@' )
101
+ values = line.split( '' )
100
102
 
101
103
  # pass 1) remove leading and trailing whitespace for values
102
104
 
@@ -107,14 +109,14 @@ class ValuesReader
107
109
 
108
110
  values = values.select do |value|
109
111
  if value =~ /^#/ ## start with # treat it as a comment column; e.g. remove it
110
- logger.debug " removing column with value >>#{value}<<"
112
+ logger.debug " removing column with value »#{value}«"
111
113
  false
112
114
  else
113
115
  true
114
116
  end
115
117
  end
116
118
 
117
- logger.debug " values: >>#{values.join('<< >>')}<<"
119
+ logger.debug " values: »#{values.join('« »')}«"
118
120
 
119
121
 
120
122
  ### todo/fix: allow check - do NOT allow mixed use of with key and w/o key
@@ -141,6 +143,15 @@ class ValuesReader
141
143
 
142
144
  attribs = {}
143
145
 
146
+ ## check title_col for grade (e.g. ***/**/*) and use returned stripped title_col if exits
147
+ grade, title_col = find_grade( title_col )
148
+
149
+ # NB: for now - do NOT include default grade e.g. if grade (***/**/*) not present; attrib will not be present too
150
+ if grade == 1 || grade == 2 || grade == 3 # grade found/present
151
+ logger.debug " found grade #{grade} in title"
152
+ attribs[:grade] = grade
153
+ end
154
+
144
155
  ## title (split of optional synonyms)
145
156
  # e.g. FC Bayern Muenchen|Bayern Muenchen|Bayern
146
157
  titles = title_col.split('|')
@@ -153,7 +164,7 @@ class ValuesReader
153
164
  if key_col == '<auto>'
154
165
  ## autogenerate key from first title
155
166
  key_col = TextUtils.title_to_key( titles[0] )
156
- logger.debug " autogen key >#{key_col}< from title >#{titles[0]}<, textutils version #{TextUtils::VERSION}"
167
+ logger.debug " autogen key »#{key_col}« from title »#{titles[0]}«, textutils version #{TextUtils::VERSION}"
157
168
  end
158
169
 
159
170
  attribs[ :key ] = key_col
@@ -1,6 +1,6 @@
1
1
 
2
2
  module TextUtils
3
3
 
4
- VERSION = '0.5.12'
4
+ VERSION = '0.5.13'
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.5.12
4
+ version: 0.5.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-09 00:00:00.000000000 Z
12
+ date: 2013-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: logutils
16
- requirement: &80007180 !ruby/object:Gem::Requirement
16
+ requirement: &83466980 !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: *80007180
24
+ version_requirements: *83466980
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rdoc
27
- requirement: &80006960 !ruby/object:Gem::Requirement
27
+ requirement: &83466720 !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: *80006960
35
+ version_requirements: *83466720
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: hoe
38
- requirement: &80006740 !ruby/object:Gem::Requirement
38
+ requirement: &83466490 !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: *80006740
46
+ version_requirements: *83466490
47
47
  description: textutils - Text Filters, Helpers, Readers and More
48
48
  email: webslideshow@googlegroups.com
49
49
  executables: []