rmtools 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/History.txt +5 -0
  2. data/Manifest.txt +84 -26
  3. data/Rakefile +7 -4
  4. data/ext/extconf.rb +1 -1
  5. data/ext/rmtools.cpp +27 -12
  6. data/ext/rmtools.h +6 -5
  7. data/lib/rmtools/b.rb +18 -0
  8. data/lib/rmtools/console/coloring.rb +72 -0
  9. data/lib/rmtools/console/highlight.rb +13 -0
  10. data/lib/rmtools/{printing.rb → console/printing.rb} +17 -2
  11. data/lib/rmtools/console.rb +1 -0
  12. data/lib/rmtools/conversions/enum.rb +23 -0
  13. data/lib/rmtools/conversions/int.rb +47 -0
  14. data/lib/rmtools/conversions/string.rb +26 -0
  15. data/lib/rmtools/conversions.rb +1 -0
  16. data/lib/rmtools/core/arguments.rb +52 -0
  17. data/lib/rmtools/{boolean.rb → core/boolean.rb} +0 -13
  18. data/lib/rmtools/core/class.rb +41 -0
  19. data/lib/rmtools/core/js.rb +45 -0
  20. data/lib/rmtools/core/kernel.rb +28 -0
  21. data/lib/rmtools/{module.rb → core/module.rb} +0 -41
  22. data/lib/rmtools/core/numeric.rb +35 -0
  23. data/lib/rmtools/{object.rb → core/object.rb} +2 -23
  24. data/lib/rmtools/core/proc.rb +18 -0
  25. data/lib/rmtools/core/regexp.rb +11 -0
  26. data/lib/rmtools/core/string_compliance.rb +31 -0
  27. data/lib/rmtools/core.rb +1 -0
  28. data/lib/rmtools/db/active_record.rb +54 -0
  29. data/lib/rmtools/db.rb +7 -0
  30. data/lib/rmtools/debug/binding.rb +56 -0
  31. data/lib/rmtools/debug/highlight.rb +23 -0
  32. data/lib/rmtools/debug/logging.rb +176 -0
  33. data/lib/rmtools/debug/present.rb +38 -0
  34. data/lib/rmtools/debug/timer.rb +19 -0
  35. data/lib/rmtools/debug/traceback.rb +92 -0
  36. data/lib/rmtools/debug.rb +1 -0
  37. data/lib/rmtools/debug_notrace.rb +1 -0
  38. data/lib/rmtools/enumerable/array.rb +134 -0
  39. data/lib/rmtools/enumerable/array_iterators.rb +33 -0
  40. data/lib/rmtools/enumerable/common.rb +49 -0
  41. data/lib/rmtools/{hash.rb → enumerable/hash.rb} +8 -8
  42. data/lib/rmtools/enumerable/object_space.rb +19 -0
  43. data/lib/rmtools/enumerable/range.rb +201 -0
  44. data/lib/rmtools/enumerable.rb +1 -0
  45. data/lib/rmtools/experimental/blackhole.rb +12 -0
  46. data/lib/rmtools/experimental/deprecation.rb +36 -0
  47. data/lib/rmtools/experimental/dumps.rb +28 -0
  48. data/lib/rmtools/{numeric.rb → experimental/numeric.rb} +22 -51
  49. data/lib/rmtools/experimental/rails_backtrace.rb +29 -0
  50. data/lib/rmtools/experimental/string.rb +56 -0
  51. data/lib/rmtools/{tree.rb → experimental/tree.rb} +0 -0
  52. data/lib/rmtools/experimental.rb +1 -0
  53. data/lib/rmtools/fs/dir.rb +89 -0
  54. data/lib/rmtools/fs/file.rb +104 -0
  55. data/lib/rmtools/fs/io.rb +58 -0
  56. data/lib/rmtools/fs/tools.rb +49 -0
  57. data/lib/rmtools/fs.rb +1 -0
  58. data/lib/rmtools/functional/fold.rb +32 -0
  59. data/lib/rmtools/{string_to_proc.rb → functional/string_to_proc.rb} +2 -22
  60. data/lib/rmtools/functional/unfold.rb +16 -0
  61. data/lib/rmtools/functional.rb +1 -0
  62. data/lib/rmtools/ip/numeric.rb +35 -0
  63. data/lib/rmtools/ip/string.rb +45 -0
  64. data/lib/rmtools/ip.rb +1 -0
  65. data/lib/rmtools/lang/ansi.rb +17 -0
  66. data/lib/rmtools/lang/cyrillic.rb +106 -0
  67. data/lib/rmtools/lang/regexp.rb +8 -0
  68. data/lib/rmtools/lang/shortcuts.rb +20 -0
  69. data/lib/rmtools/lang.rb +1 -0
  70. data/lib/rmtools/rand/array.rb +39 -0
  71. data/lib/rmtools/rand/enum.rb +26 -0
  72. data/lib/rmtools/rand/range.rb +13 -0
  73. data/lib/rmtools/{random.rb → rand/string.rb} +13 -107
  74. data/lib/rmtools/rand.rb +1 -0
  75. data/lib/rmtools/require.rb +13 -0
  76. data/lib/rmtools/setup.rb +6 -5
  77. data/lib/rmtools/text/string_parse.rb +60 -0
  78. data/lib/rmtools/{stringscanner.rb → text/string_scanner.rb} +3 -2
  79. data/lib/rmtools/text/string_simple.rb +75 -0
  80. data/lib/rmtools/text/string_split.rb +148 -0
  81. data/lib/rmtools/text/textilize.rb +44 -0
  82. data/lib/rmtools/text.rb +1 -0
  83. data/lib/rmtools/time/global.rb +17 -0
  84. data/lib/rmtools/time/russian.rb +47 -0
  85. data/lib/rmtools/time.rb +1 -32
  86. data/lib/rmtools/xml/document.rb +28 -0
  87. data/lib/rmtools/xml/finders.rb +84 -0
  88. data/lib/rmtools/xml/libxml.rb +11 -0
  89. data/lib/rmtools/xml/node.rb +196 -0
  90. data/lib/rmtools/xml/string.rb +43 -0
  91. data/lib/rmtools/xml/xpath.rb +32 -0
  92. data/lib/rmtools/xml.rb +7 -0
  93. data/lib/rmtools.rb +8 -44
  94. metadata +97 -72
  95. data/lib/rmtools/arguments.rb +0 -24
  96. data/lib/rmtools/array.rb +0 -189
  97. data/lib/rmtools/binding.rb +0 -23
  98. data/lib/rmtools/coloring.rb +0 -82
  99. data/lib/rmtools/cyr-time.rb +0 -49
  100. data/lib/rmtools/cyrilic.rb +0 -124
  101. data/lib/rmtools/dumps.rb +0 -192
  102. data/lib/rmtools/enum.rb +0 -90
  103. data/lib/rmtools/io.rb +0 -303
  104. data/lib/rmtools/js.rb +0 -25
  105. data/lib/rmtools/limited_string.rb +0 -17
  106. data/lib/rmtools/logging.rb +0 -158
  107. data/lib/rmtools/proc.rb +0 -25
  108. data/lib/rmtools/range.rb +0 -100
  109. data/lib/rmtools/string.rb +0 -276
  110. data/lib/rmtools/traceback.rb +0 -106
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmtools
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
4
+ hash: 19
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Shinku Templar
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-10 00:00:00 +03:00
18
+ date: 2011-02-03 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -42,62 +42,30 @@ dependencies:
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- hash: 9
45
+ hash: 19
46
46
  segments:
47
47
  - 2
48
48
  - 3
49
- - 5
50
- version: 2.3.5
49
+ - 8
50
+ version: 2.3.8
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency
54
- name: rubyforge
54
+ name: hoe
55
55
  prerelease: false
56
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- hash: 7
61
+ hash: 43
62
62
  segments:
63
63
  - 2
64
+ - 9
64
65
  - 0
65
- - 4
66
- version: 2.0.4
66
+ version: 2.9.0
67
67
  type: :development
68
68
  version_requirements: *id003
69
- - !ruby/object:Gem::Dependency
70
- name: gemcutter
71
- prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- hash: 11
78
- segments:
79
- - 0
80
- - 5
81
- - 0
82
- version: 0.5.0
83
- type: :development
84
- version_requirements: *id004
85
- - !ruby/object:Gem::Dependency
86
- name: hoe
87
- prerelease: false
88
- requirement: &id005 !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- hash: 27
94
- segments:
95
- - 2
96
- - 5
97
- - 0
98
- version: 2.5.0
99
- type: :development
100
- version_requirements: *id005
101
69
  description: "== RMTools\n\
102
70
  Methods for basic classes addon collection.\n\n\
103
71
  == CHANGES\n\
@@ -118,34 +86,92 @@ files:
118
86
  - ext/rmtools.h
119
87
  - ext/rmtools.cpp
120
88
  - lib/rmtools.rb
121
- - lib/rmtools/arguments.rb
122
- - lib/rmtools/numeric.rb
123
- - lib/rmtools/string.rb
124
- - lib/rmtools/io.rb
125
- - lib/rmtools/js.rb
126
- - lib/rmtools/cyrilic.rb
127
- - lib/rmtools/coloring.rb
128
- - lib/rmtools/stringscanner.rb
129
- - lib/rmtools/enum.rb
130
- - lib/rmtools/string_to_proc.rb
131
- - lib/rmtools/traceback.rb
89
+ - lib/rmtools/db/active_record.rb
90
+ - lib/rmtools/fs/io.rb
91
+ - lib/rmtools/fs/file.rb
92
+ - lib/rmtools/fs/dir.rb
93
+ - lib/rmtools/fs/tools.rb
94
+ - lib/rmtools/ip/numeric.rb
95
+ - lib/rmtools/ip/string.rb
96
+ - lib/rmtools/xml/xpath.rb
97
+ - lib/rmtools/xml/string.rb
98
+ - lib/rmtools/xml/libxml.rb
99
+ - lib/rmtools/xml/finders.rb
100
+ - lib/rmtools/xml/node.rb
101
+ - lib/rmtools/xml/document.rb
102
+ - lib/rmtools/b.rb
103
+ - lib/rmtools/core/arguments.rb
104
+ - lib/rmtools/core/numeric.rb
105
+ - lib/rmtools/core/js.rb
106
+ - lib/rmtools/core/string_compliance.rb
107
+ - lib/rmtools/core/kernel.rb
108
+ - lib/rmtools/core/boolean.rb
109
+ - lib/rmtools/core/module.rb
110
+ - lib/rmtools/core/object.rb
111
+ - lib/rmtools/core/regexp.rb
112
+ - lib/rmtools/core/class.rb
113
+ - lib/rmtools/core/proc.rb
114
+ - lib/rmtools/lang/shortcuts.rb
115
+ - lib/rmtools/lang/ansi.rb
116
+ - lib/rmtools/lang/regexp.rb
117
+ - lib/rmtools/lang/cyrillic.rb
118
+ - lib/rmtools/rand/string.rb
119
+ - lib/rmtools/rand/enum.rb
120
+ - lib/rmtools/rand/range.rb
121
+ - lib/rmtools/rand/array.rb
122
+ - lib/rmtools/text/string_simple.rb
123
+ - lib/rmtools/text/string_scanner.rb
124
+ - lib/rmtools/text/textilize.rb
125
+ - lib/rmtools/text/string_split.rb
126
+ - lib/rmtools/text/string_parse.rb
127
+ - lib/rmtools/time/russian.rb
128
+ - lib/rmtools/time/global.rb
129
+ - lib/rmtools/rand.rb
130
+ - lib/rmtools/console/coloring.rb
131
+ - lib/rmtools/console/printing.rb
132
+ - lib/rmtools/console/highlight.rb
133
+ - lib/rmtools/core.rb
134
+ - lib/rmtools/db.rb
135
+ - lib/rmtools/debug/present.rb
136
+ - lib/rmtools/debug/traceback.rb
137
+ - lib/rmtools/debug/binding.rb
138
+ - lib/rmtools/debug/logging.rb
139
+ - lib/rmtools/debug/highlight.rb
140
+ - lib/rmtools/debug/timer.rb
141
+ - lib/rmtools/fs.rb
142
+ - lib/rmtools/ip.rb
143
+ - lib/rmtools/lang.rb
144
+ - lib/rmtools/functional.rb
145
+ - lib/rmtools/experimental.rb
146
+ - lib/rmtools/functional/string_to_proc.rb
147
+ - lib/rmtools/functional/fold.rb
148
+ - lib/rmtools/functional/unfold.rb
149
+ - lib/rmtools/text.rb
150
+ - lib/rmtools/console.rb
132
151
  - lib/rmtools/time.rb
133
- - lib/rmtools/random.rb
134
- - lib/rmtools/binding.rb
135
- - lib/rmtools/printing.rb
136
- - lib/rmtools/range.rb
137
- - lib/rmtools/tree.rb
138
- - lib/rmtools/boolean.rb
139
- - lib/rmtools/hash.rb
140
- - lib/rmtools/logging.rb
141
- - lib/rmtools/limited_string.rb
142
- - lib/rmtools/module.rb
143
- - lib/rmtools/object.rb
144
- - lib/rmtools/array.rb
152
+ - lib/rmtools/debug_notrace.rb
153
+ - lib/rmtools/debug.rb
154
+ - lib/rmtools/enumerable/common.rb
155
+ - lib/rmtools/enumerable/range.rb
156
+ - lib/rmtools/enumerable/hash.rb
157
+ - lib/rmtools/enumerable/array.rb
158
+ - lib/rmtools/enumerable/object_space.rb
159
+ - lib/rmtools/enumerable/array_iterators.rb
160
+ - lib/rmtools/require.rb
161
+ - lib/rmtools/experimental/numeric.rb
162
+ - lib/rmtools/experimental/string.rb
163
+ - lib/rmtools/experimental/blackhole.rb
164
+ - lib/rmtools/experimental/tree.rb
165
+ - lib/rmtools/experimental/deprecation.rb
166
+ - lib/rmtools/experimental/dumps.rb
167
+ - lib/rmtools/experimental/rails_backtrace.rb
168
+ - lib/rmtools/xml.rb
169
+ - lib/rmtools/conversions.rb
145
170
  - lib/rmtools/setup.rb
146
- - lib/rmtools/cyr-time.rb
147
- - lib/rmtools/dumps.rb
148
- - lib/rmtools/proc.rb
171
+ - lib/rmtools/conversions/string.rb
172
+ - lib/rmtools/conversions/enum.rb
173
+ - lib/rmtools/conversions/int.rb
174
+ - lib/rmtools/enumerable.rb
149
175
  - ./Rakefile
150
176
  - ./Manifest.txt
151
177
  - ./License.txt
@@ -161,7 +187,6 @@ rdoc_options:
161
187
  - README.txt
162
188
  require_paths:
163
189
  - lib
164
- - ext
165
190
  required_ruby_version: !ruby/object:Gem::Requirement
166
191
  none: false
167
192
  requirements:
@@ -183,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
208
  requirements: []
184
209
 
185
210
  rubyforge_project: rmtools
186
- rubygems_version: 1.3.7
211
+ rubygems_version: 1.4.2
187
212
  signing_key:
188
213
  specification_version: 3
189
214
  summary: Yet another Ruby applied framework
@@ -1,24 +0,0 @@
1
- class Array
2
-
3
- def fetch_opts(defaults=[], opts={})
4
- if opts and self[-1].is(Hash) and !defaults[size-1].is(Hash)
5
- opts = opts.merge pop
6
- end
7
- each_index {|i| import(defaults, i) if self[i] == :def}
8
- defaults.slice! 0, size
9
- concat defaults << opts
10
- end
11
- alias :get_opts :fetch_opts
12
-
13
- def valid_types(pattern_ary)
14
- each_with_index.find {|var, i|
15
- pattern = pattern_ary[i]
16
- if pattern.is Array
17
- pattern.find {|j| !(pattern[j] === var[i])}
18
- else !(pattern === var[i])
19
- end
20
- }
21
- end
22
-
23
- end
24
-
data/lib/rmtools/array.rb DELETED
@@ -1,189 +0,0 @@
1
- # encoding: utf-8
2
- class Array
3
-
4
- def avg
5
- sum.to_f/size
6
- end
7
-
8
- def scale(top)
9
- case top
10
- when Numeric; ratio = max.to_f/top
11
- when Array; ratio = zip(top).map {|a,b| b ? a.to_f/b : 0}.max
12
- else raise TypeError, "number or array of numbers expceted, #{top.class} given"
13
- end
14
- map {|e| e/ratio}
15
- end
16
-
17
- def sorted_uniq_by(&block)
18
- uniq_by(&block).sort_by(&block)
19
- end
20
-
21
- def recursive_find(&b)
22
- res = nil
23
- each {|e|
24
- return e if b[e]
25
- if e.resto :recursive_find
26
- res = e.recursive_find(&b)
27
- return res if res
28
- end
29
- }
30
- res
31
- end
32
-
33
- def recursive_find_all(&b)
34
- res = []
35
- each {|e|
36
- res << e if b[e]
37
- if e.resto :recursive_find
38
- res.concat e.recursive_find_all(&b)
39
- end
40
- }
41
- res.uniq
42
- end
43
-
44
- def set(value, &block)
45
- return unless e = find(&block)
46
- self[index(e)] = value
47
- end
48
-
49
- def set_all(value, &block)
50
- find_all(&block).each {|e| self[index(e)] = value}
51
- end
52
-
53
- def indice(&block)
54
- return unless e = find(&block)
55
- index(e)
56
- end
57
- alias :pos :indice
58
-
59
- def indices(&block)
60
- i = nil
61
- find_all(&block).map {|e|
62
- i = i ?
63
- self[i+1..-1].index(e) + i + 1 :
64
- index(e)
65
- }
66
- end
67
-
68
- def div(int, to_int_parts=nil)
69
- len = int.to_i
70
- return [self] if len <= 0
71
- arr = dup
72
- newarr = []
73
- while arr.size > 0
74
- newarr << arr.slice!(0, len)
75
- end
76
- newarr
77
- end
78
-
79
- def div!(int, to_int_parts=nil)
80
- len = int.to_i
81
- return [self] if len <= 0
82
- arr = dup
83
- clear
84
- while arr.size > 0
85
- self << arr.slice!(0, len)
86
- end
87
- self
88
- end
89
-
90
- def to_dict
91
- newhash = {}
92
- list = dup
93
- list.each {|gr|
94
- desc = gr.shift
95
- gr.each {|ex| newhash[ex] = desc}
96
- }
97
- newhash
98
- end
99
-
100
- def compile_int(base=10)
101
- int = 0
102
- pos = size
103
- each {|i| int += base**(pos -= 1) * i}
104
- int
105
- end
106
-
107
- def uniq?
108
- uniq == self
109
- end
110
-
111
- def odds
112
- newarr = []
113
- each_with_index {|e, i| newarr << e if i%2 == 1}
114
- newarr
115
- end
116
-
117
- def evens
118
- newarr = []
119
- each_with_index {|e, i| newarr << e if i%2 == 0}
120
- newarr
121
- end
122
-
123
- def map_hash &b
124
- Hash[map(&b)]
125
- end
126
-
127
- def flatmap &b
128
- ary = []
129
- each {|e| ary.concat yield e}
130
- ary
131
- end
132
-
133
- # analogue to String#>>
134
- def >>(ary)
135
- ary.replace(self + ary)
136
- end
137
-
138
- alias :casecmp :===
139
- # making multiple pattern matching possible:
140
- # a, b = '3', '10'
141
- # case [a, b]
142
- # when [Integer, Integer]; a+b
143
- # when [/\d/, '10']; '%*d'%[a, b]
144
- # ...
145
- # end
146
- def ===(obj)
147
- return true if casecmp(obj)
148
- !!(if obj.kinda(Array) and obj.size == size
149
- each_with_index {|e, i| e == :_ or e === obj[i] or return false}
150
- end)
151
- end
152
-
153
- def sum(identity=0, &b) foldl(:+, &b) || identity end
154
-
155
- # should override slower active support's method
156
- def group_by(&b) count :group, &b end
157
-
158
- if RUBY_VERSION < "1.8.7"
159
- def map_with_index
160
- a = []
161
- each_with_index {|e, i| a << yield(e, i)}
162
- a
163
- end
164
- else
165
- def map_with_index(&block)
166
- each_with_index.map(&block)
167
- end
168
- end
169
-
170
- if !defined? RMTools::Iterators
171
- alias :throw_no :method_missing
172
- RMTools::Iterators = %r{(#{(%w{select reject partition find_all find sum foldr min max flatmap}+instance_methods.grep(/_by$/))*'|'})_([\w\d\_]+[!?]?)}
173
-
174
- def method_missing(method, *args, &block)
175
- if match = (meth = method.to_s).match(RMTools::Iterators)
176
- iterator, meth = match[1..2]
177
- meth = meth.to_sym
178
- return send(iterator) {|i| i.__send__ meth, *args, &block}
179
- elsif meth.sub!(/sses([!?]?)$/, 'ss\1') or meth.sub!(/ies([!?]?)$/, 'y\1') or meth.sub!(/s([!?]?)$/, '\1')
180
- return map {|i| i.__send__ meth.to_sym, *args, &block}
181
- else
182
- throw_no method
183
- end
184
- rescue NoMethodError
185
- throw_no method
186
- end
187
- end
188
-
189
- end
@@ -1,23 +0,0 @@
1
- class Binding
2
-
3
- def inspect_local_variables
4
- vars = self.eval('local_variables') # ['a', 'b']
5
- values = self.eval "[#{vars * ','}]" # ["a's value", "b's value"]
6
- Hash[vars.zip(values)]
7
- end
8
-
9
- def inspect_instance_variables
10
- vars = self.eval('instance_variables') # ['@a', '@b']
11
- values = self.eval "[#{vars * ','}]" # ["@a's value", "@b's value"]
12
- Hash[vars.zip(values)]
13
- end
14
-
15
- def inspect_env
16
- self.eval("{'self' => self}").merge(inspect_local_variables).merge(inspect_instance_variables)
17
- end
18
-
19
- def valid_types(pattern_ary)
20
- self.eval("[#{self.eval('local_variables')*','}]").valid_types(pattern_ary)
21
- end
22
-
23
- end
@@ -1,82 +0,0 @@
1
- # encoding: utf-8
2
- module RMTools
3
-
4
- class Coloring
5
- __init__
6
- method_defined? :b and undef_method :b
7
- method_defined? :p and undef_method :p
8
-
9
- if !defined? ::BOLD
10
- BOLD = 1
11
- UNDERLINE = 4
12
- GRAYBG = 5
13
- BOLDBG = 7
14
-
15
- KEY = BLACK = 30
16
- RED = 31
17
- GREEN = 32
18
- YELLOW = 33
19
- BLUE = 34
20
- PURPLE = 35
21
- CYAN = 36
22
- GRAY = 37
23
-
24
- Colors = {:black => 30, :red => 31, :green => 32, :yellow => 33, :blue => 34, :purple => 35, :cyan => 36, :gray => 37,
25
- :k => 30, :r => 31, :g => 32, :y => 33, :b => 34, :p => 35, :c => 36
26
- }.unify_strs
27
- Effects = {:bold => 1, :underline => 4, :graybg => 5, :boldbg => 7,
28
- :b => 1, :u => 4, :gbg => 5, :bbg => 7
29
- }.unify_strs end
30
-
31
- def paint(str, num=nil, effect=nil)
32
- # default cmd.exe cannot into ANSI
33
- return str if ENV['ComSpec'] =~ /cmd(.exe)?$/
34
- num = Colors[num] if num.is String
35
- effect = Effects[effect] if effect.is String
36
- if num and effect
37
- "\e[#{effect};#{num}m#{str}\e[m"
38
- elsif effect
39
- "\e[#{effect}m#{str}\e[m"
40
- elsif num
41
- "\e[#{num}m#{str}\e[m"
42
- else str
43
- end
44
- end
45
-
46
- def method_missing(m, str)
47
- paint str, *(m.to_s/"_")
48
- end
49
-
50
- def clean str
51
- str.gsub(/\e\[.*?m/, '')
52
- end
53
-
54
- end
55
-
56
- Painter = Coloring.new
57
- ['sub', 'gsub', 'sub!', 'gsub!'].each {|m| Coloring.module_eval "
58
- def #{m.sub 'sub', 'hl'} str, pattern, color=:red_bold
59
- str.#{m}(pattern) {|word| send color, word}
60
- end
61
- "
62
- module_eval "
63
- def #{m.sub 'sub', 'hl'} str, pattern, color=:red_bold
64
- str.#{m}(pattern) {|word| Painter.send color, word}
65
- end
66
- "
67
- # module_function m.to_sym
68
- }
69
-
70
- end
71
-
72
- class String
73
-
74
- def find_hl(pat, range=1000) idx = case pat
75
- when String; index pat
76
- when Regexp; self =~ pat
77
- else raise TypeError, "pattern must be string or regexp"
78
- end
79
- puts RMTools.ghl(self[[idx-range, 0].max, 2*range], pat)
80
- end
81
-
82
- end
@@ -1,49 +0,0 @@
1
- # coding: utf-8
2
-
3
- class String
4
-
5
- def digit_date
6
- gsub(/jan|[яЯ][нН][вВ]([аА][рР][яЯьЬ]?)?/i, '01').
7
- gsub(/feb|[фФ][еЕ][вВ]([рР][аА][лЛ][яЯьЬ]?)?/i, '02').
8
- gsub(/mar|[мМ][аА][рР]([тТ][аА]?)?/i, '03').
9
- gsub(/apr|[аА][пП][рР]([еЕ][лЛ][яЯьЬ]?)?/i, '04').
10
- gsub(/may|[мМ][аА][яЯйЙ]?/i, '05').
11
- gsub(/june?|[иИ][юЮ][нН][яЯьЬ]?/i, '06').
12
- gsub(/july?|[иИ][юЮ][лЛ][яЯьЬ]?/i, '07').
13
- gsub(/aug|[аА][вВ][гГ]([уУ][сС][тТ][аА]?)?/i, '08').
14
- gsub(/sep|[сС][еЕ][нН]([тТ][яЯ][бБ][рР][яЯьЬ]?)?/i, '09').
15
- gsub(/oct|[оО][кК][тТ]([яЯ][бБ][рР][яЯьЬ]?)?/i, '10').
16
- gsub(/nov|[нН][оО][яЯ]([бБ][рР][яЯьЬ]?)?/i, '11').
17
- gsub(/dec|[дД][еЕ][кК]([аА][бБ][рР][яЯьЬ]?)?/i, '12')
18
- end
19
- alias digitize digit_date
20
-
21
- def tr_date
22
- gsub(/[яЯ][нН][вВ]([аА][рР][яЯьЬ]?)?/, 'jan').
23
- gsub(/[фФ][еЕ][вВ]([рР][аА][лЛ][яЯьЬ]?)?/, 'feb').
24
- gsub(/[мМ][аА][рР]([тТ][аА]?)?/, 'mar').
25
- gsub(/[аА][пП][рР]([еЕ][лЛ][яЯьЬ]?)?/, 'apr').
26
- gsub(/[мМ][аА][яЯйЙ]?/, 'may').
27
- gsub(/[иИ][юЮ][нН][яЯьЬ]?/, 'jun').
28
- gsub(/[иИ][юЮ][лЛ][яЯьЬ]?/, 'jul').
29
- gsub(/[аА][вВ][гГ]([уУ][сС][тТ][аА]?)?/, 'aug').
30
- gsub(/[сС][еЕ][нН]([тТ][яЯ][бБ][рР][яЯьЬ]?)?/, 'sep').
31
- gsub(/[оО][кК][тТ]([яЯ][бБ][рР][яЯьЬ]?)?/, 'oct').
32
- gsub(/[нН][оО][яЯ]([бБ][рР][яЯьЬ]?)?/, 'nov').
33
- gsub(/[дД][еЕ][кК]([аА][бБ][рР][яЯьЬ]?)?/, 'dec')
34
- end
35
-
36
- def digit_nums
37
- gsub(/[оО][дД][иИ][нН]|[еЕ][дД][иИ][нН][иИ][цЦ][аА]/, '1').
38
- gsub(/[дД][вВ]([оО][йЙ][кК])?[аА]/, '2').
39
- gsub(/[тТ][рР]([иИ]|[оО][йЙ][кК][аА])/, '3').
40
- gsub(/[чЧ][еЕ][тТ]([ыЫ][рР][еЕ]|[вВ][еЕёЁ][рР][кК][аА])/, '4').
41
- gsub(/[пП][яЯ][тТ]([ьЬ]|[еЕёЁ][рР][кК][аА])/, '5').
42
- gsub(/[шШ][еЕ][сС][тТ]([ьЬ]|[еЕёЁ][рР][кК][аА])/, '6').
43
- gsub(/[сС][еЕ][мМ]([ьЬ]|[еЕёЁ][рР][кК][аА])/, '7').
44
- gsub(/[вВ][оО][сС]([еЕ][мМ][ьЬ]|[ьЬ][мМ][еЕёЁ][рР][кК][аА])/i, '8').
45
- gsub(/[дД][еЕ][вВ][яЯ][тТ]([ьЬ]|[кК][аА])/, '9').
46
- gsub(/[нН][оОуУ][лЛ][ьЬ]/, '0')
47
- end
48
-
49
- end