textutils 0.3.0 → 0.4.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.
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ Hoe.spec 'textutils' do
18
18
  self.history_file = 'History.markdown'
19
19
 
20
20
  self.extra_deps = [
21
- ['logutils', '~> 0.2.0']
21
+ ['logutils', '>= 0.3.0']
22
22
  ]
23
23
 
24
24
  self.licenses = ['Public Domain']
@@ -2,22 +2,19 @@
2
2
 
3
3
  class CodeReader
4
4
 
5
- def initialize( logger=nil, path )
6
- if logger.nil?
7
- @logger = Logger.new(STDOUT)
8
- @logger.level = Logger::INFO
9
- else
10
- @logger = logger
11
- end
5
+ def logger
6
+ @logger ||= LogUtils[ self ]
7
+ end
12
8
 
13
- @path = path
9
+ def initialize( path )
10
+ @path = path
14
11
 
15
12
  ## nb: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
16
13
  ## - see worlddb/utils.rb
17
14
 
18
15
  @code = File.read_utf8( @path )
19
16
  end
20
-
17
+
21
18
  def eval( klass )
22
19
  klass.class_eval( @code )
23
20
 
@@ -29,6 +26,4 @@ class CodeReader
29
26
  # end
30
27
  end
31
28
 
32
- attr_reader :logger
33
-
34
29
  end # class CodeReader
@@ -3,14 +3,11 @@
3
3
 
4
4
  class HashReader
5
5
 
6
- def initialize( logger=nil, path )
7
- if logger.nil?
8
- @logger = Logger.new(STDOUT)
9
- @logger.level = Logger::INFO
10
- else
11
- @logger = logger
12
- end
13
-
6
+ def logger
7
+ @logger ||= LogUtils[ self ]
8
+ end
9
+
10
+ def initialize( path )
14
11
  @path = path
15
12
 
16
13
  ## nb: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
@@ -34,7 +31,7 @@ class HashReader
34
31
  ## nb: yaml does NOT support tabs see why here -> yaml.org/faq.html
35
32
 
36
33
  text = text.gsub( "\t" ) do |_|
37
- puts "*** warn: hash reader - found tab (\t) replacing w/ two spaces; yaml forbids tabs; see yaml.org/faq.html"
34
+ logger.warn "hash reader - found tab (\t) replacing w/ two spaces; yaml forbids tabs; see yaml.org/faq.html"
38
35
  ' ' # replace w/ two spaces
39
36
  end
40
37
 
@@ -44,7 +41,7 @@ class HashReader
44
41
  ## no: no
45
42
 
46
43
  text = text.gsub( /^([ ]*)(ON|On|on|NO|No|no|N|n|Y|y)[ ]*:/ ) do |value|
47
- puts "*** warn: hash reader - found implicit bool (#{$1}#{$2}) for key; adding quotes to turn into string; see yaml.org/refcard.html"
44
+ logger.warn "hash reader - found implicit bool (#{$1}#{$2}) for key; adding quotes to turn into string; see yaml.org/refcard.html"
48
45
  # nb: preserve leading spaces for structure - might be significant
49
46
  "#{$1}'#{$2}':" # add quotes to turn it into a string (not bool e.g. true|false)
50
47
  end
@@ -54,16 +51,13 @@ class HashReader
54
51
  ## key: nb,nn,no,se => nb,nn,'no',se -- avoid!!
55
52
 
56
53
  text = text.gsub( /:[ ]+(ON|On|on|NO|No|no|N|n|Y|y)[ ]*($| #.*$)/ ) do |value|
57
- puts "*** warn: hash reader - found implicit bool (#{$1}) for value; adding quotes to turn into string; see yaml.org/refcard.html"
54
+ logger.warn "hash reader - found implicit bool (#{$1}) for value; adding quotes to turn into string; see yaml.org/refcard.html"
58
55
  ": '#{$1}'" # add quotes to turn it into a string (not bool e.g. true|false)
59
56
  end
60
57
 
61
58
 
62
59
  @hash = YAML.load( text )
63
60
  end
64
-
65
- attr_reader :logger
66
-
67
61
 
68
62
  ###
69
63
  # nb: returns all values as strings
@@ -77,7 +71,7 @@ class HashReader
77
71
  key = key_wild.to_s.strip
78
72
  value = value_wild.to_s.strip
79
73
 
80
- puts "yaml key:#{key_wild.class.name} >>#{key}<<, value:#{value_wild.class.name} >>#{value}<<"
74
+ logger.debug "yaml key:#{key_wild.class.name} >>#{key}<<, value:#{value_wild.class.name} >>#{value}<<"
81
75
 
82
76
  yield( key, value )
83
77
  end
@@ -100,7 +94,7 @@ class HashReader
100
94
  value = value_wild
101
95
  end
102
96
 
103
- puts "yaml key:#{key_wild.class.name} >>#{key}<<, value:#{value_wild.class.name} >>#{value}<<"
97
+ logger.debug "yaml key:#{key_wild.class.name} >>#{key}<<, value:#{value_wild.class.name} >>#{value}<<"
104
98
 
105
99
  yield( key, value )
106
100
  end
@@ -6,18 +6,13 @@
6
6
 
7
7
  class StringLineReader
8
8
 
9
- def initialize( logger=nil, data )
10
- if logger.nil?
11
- @logger = Logger.new(STDOUT)
12
- @logger.level = Logger::INFO
13
- else
14
- @logger = logger
15
- end
16
-
17
- @data = data
9
+ def logger
10
+ @logger ||= LogUtils[ self ]
18
11
  end
19
12
 
20
- attr_reader :logger
13
+ def initialize( data )
14
+ @data = data
15
+ end
21
16
 
22
17
 
23
18
  def each_line
@@ -47,14 +42,11 @@ end
47
42
 
48
43
  class LineReader
49
44
 
50
- def initialize( logger=nil, path )
51
- if logger.nil?
52
- @logger = Logger.new(STDOUT)
53
- @logger.level = Logger::INFO
54
- else
55
- @logger = logger
56
- end
57
-
45
+ def logger
46
+ @logger ||= LogUtils[ self ]
47
+ end
48
+
49
+ def initialize( path )
58
50
  @path = path
59
51
 
60
52
  ## nb: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
@@ -62,9 +54,6 @@ class LineReader
62
54
  @data = File.read_utf8( @path )
63
55
  end
64
56
 
65
- attr_reader :logger
66
-
67
-
68
57
  def each_line
69
58
  @data.each_line do |line|
70
59
 
@@ -2,15 +2,11 @@
2
2
 
3
3
  class ValuesReader
4
4
 
5
- def initialize( logger, path, more_values={} )
6
- ## todo: check - can we make logger=nil a default arg too?
7
- if logger.nil?
8
- @logger = Logger.new(STDOUT)
9
- @logger.level = Logger::INFO
10
- else
11
- @logger = logger
12
- end
13
-
5
+ def logger
6
+ @logger ||= LogUtils[ self ]
7
+ end
8
+
9
+ def initialize( path, more_values={} )
14
10
  @path = path
15
11
 
16
12
  @more_values = more_values
@@ -18,8 +14,6 @@ class ValuesReader
18
14
  @data = File.read_utf8( @path )
19
15
  end
20
16
 
21
- attr_reader :logger
22
-
23
17
  def each_line
24
18
 
25
19
  @data.each_line do |line|
@@ -47,7 +41,7 @@ class ValuesReader
47
41
 
48
42
  line = line.strip
49
43
 
50
- puts "line: >>#{line}<<"
44
+ logger.debug "line: >>#{line}<<"
51
45
 
52
46
  values = line.split(',')
53
47
 
@@ -60,14 +54,14 @@ class ValuesReader
60
54
 
61
55
  values = values.select do |value|
62
56
  if value =~ /^#/ ## start with # treat it as a comment column; e.g. remove it
63
- puts " removing column with value >>#{value}<<"
57
+ logger.debug " removing column with value >>#{value}<<"
64
58
  false
65
59
  else
66
60
  true
67
61
  end
68
62
  end
69
63
 
70
- puts " values: >>#{values.join('<< >>')}<<"
64
+ logger.debug " values: >>#{values.join('<< >>')}<<"
71
65
 
72
66
 
73
67
  ### todo/fix: allow check - do NOT allow mixed use of with key and w/o key
@@ -103,7 +97,7 @@ class ValuesReader
103
97
  if key_col == '<auto>'
104
98
  ## autogenerate key from first title
105
99
  key_col = title_to_key( titles[0] )
106
- puts " autogen key >#{key_col}< from title >#{titles[0]}<"
100
+ logger.debug " autogen key >#{key_col}< from title >#{titles[0]}<"
107
101
  end
108
102
 
109
103
  attribs[ :key ] = key_col
@@ -171,5 +165,4 @@ class ValuesReader
171
165
  key
172
166
  end # method title_to_key
173
167
 
174
-
175
168
  end # class ValuesReader
@@ -1,7 +1,7 @@
1
1
 
2
2
  module TextUtils
3
3
 
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
 
6
6
  end # module TextUtils
7
7
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: textutils
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gerald Bauer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-02-20 00:00:00 Z
18
+ date: 2013-02-21 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: logutils
@@ -23,14 +23,14 @@ dependencies:
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - ~>
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
- hash: 23
28
+ hash: 19
29
29
  segments:
30
30
  - 0
31
- - 2
31
+ - 3
32
32
  - 0
33
- version: 0.2.0
33
+ version: 0.3.0
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency