rmtools 1.2.11 → 1.2.12

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/README.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2012
1
+ Copyright (c) 2010-2013
2
2
  Baev Sergey <tinbka@gmail.com>
3
3
 
4
4
  This work is licensed under the same license as Ruby language.
@@ -9,6 +9,13 @@ Methods for basic classes addon collection.
9
9
 
10
10
  == CHANGES
11
11
 
12
+ == Version 1.2.12
13
+
14
+ * Smartified Array bicycles: #index_where, #indices_where, #set_where, #set_all_where, #del_where, #del_all_where
15
+ * Added #arrange_by to Array enumerators
16
+ * Updated detecting of xml charset encoding for ruby 1.9
17
+ * Fixed bug with empty trace formatting and Array#get_args with non-equalable argument
18
+
12
19
  == Version 1.2.11
13
20
 
14
21
  * Added Array#select_by and #reject_by pattern-iterators
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rake'
2
2
  require './lib/rmtools/install'
3
3
  compile_manifest
4
4
 
5
- RMTOOLS_VERSION = '1.2.11'
5
+ RMTOOLS_VERSION = '1.2.12'
6
6
  begin
7
7
  require 'hoe'
8
8
  config = Hoe.spec 'rmtools' do
@@ -11,7 +11,7 @@ begin
11
11
  self.summary = 'Yet another Ruby applied lib'
12
12
  self.description = 'Applied library primarily for debug and text/arrays/files processing purposes.'
13
13
  self.changes = paragraphs_of('README.txt', 5..-1).join("\n\n")
14
- self.url = 'http://github.com/tinbka'
14
+ self.urls = ['https://github.com/tinbka/rmtools']
15
15
 
16
16
  self.extra_deps = [['rake','>= 0.8.7'], ['activesupport','>= 2.3.8']]
17
17
  end
@@ -33,7 +33,7 @@ class Array
33
33
  self[flags] = []
34
34
  end
35
35
  end
36
- each_index {|i| import(defaults, i) if self[i] == :def}
36
+ each_index {|i| import(defaults, i) if :def == self[i]}
37
37
  defaults.slice! 0, size
38
38
  concat defaults << opts
39
39
  end
@@ -23,6 +23,7 @@ module RMTools
23
23
  IgnoreFiles = %r{#{Regexp.escape $:.grep(%r{/ruby/1\.(8|9\.\d)$})[0]}/irb(/|\.rb$)|/active_support/dependencies.rb$}
24
24
 
25
25
  def format_trace(a)
26
+ return [] if !a.b
26
27
  bt, steps, i = [], [], 0
27
28
  m = a[0].parse:caller
28
29
  # seems like that bug is fixed for now
@@ -82,32 +82,42 @@ class Array
82
82
  end
83
83
 
84
84
 
85
- # setters/getters
85
+ # setters/getters/deleters
86
86
  def set_where(value, &block)
87
- return unless e = find(&block)
88
- self[index(e)] = value
87
+ each_with_index {|e, i| return self[i] = value if block[e]}
88
+ nil
89
89
  end
90
90
 
91
91
  def set_all_where(value, &block)
92
- select(&block).each {|e| self[index(e)] = value}
92
+ #select(&block).each {|e| self[index(e)] = value} # 3.643
93
+ #each_with_index {|e, i| self[i] = value if block[e]} # 0.240
94
+ # велосипедист, бля
95
+ map! {|e| block[e] ? value : e} # 0.168
93
96
  end
94
97
 
95
- def indice_where(&block)
96
- return unless e = find(&block)
97
- index(e)
98
+ def index_where(&block)
99
+ each_with_index {|e, i| return i if block[e]}
100
+ nil
98
101
  end
99
- alias :pos :indice_where
102
+ alias :pos :index_where
100
103
 
101
104
  def indices_where(&block)
102
- i = nil
103
- find_all(&block).map {|e|
104
- i = i ?
105
- self[i+1..-1].index(e) + i + 1 :
106
- index(e)
107
- }
105
+ a = []
106
+ each_with_index {|e, i| a << i if block[e]}
107
+ a
108
+ end
109
+
110
+ def del_where(&block)
111
+ each_with_index {|e, i| return delete_at i if block[e]}
112
+ nil
113
+ end
114
+
115
+ def del_all_where(&block)
116
+ reject!(&block)
108
117
  end
109
118
 
110
119
 
120
+
111
121
  # splitters
112
122
  def div(int, to_int_parts=nil)
113
123
  len = int.to_i
@@ -14,7 +14,8 @@ unless defined? RMTools::Iterators
14
14
  # => [[1, 2, 3], [3, 4, 6]]
15
15
  class Array
16
16
  alias :throw_no :method_missing
17
- RMTools::Iterators = %r{^(#{(instance_methods.grep(/_by$/)+%w{every no select reject partition find_all find sum foldr find_by select_by reject_by})*'|'})_([\w\d\_]+[!?]?)}
17
+ alias :arrange_by :arrange
18
+ RMTools::Iterators = %r{^(#{(my_methods(/_by$/)+%w{every no select reject partition find_all find sum foldr})*'|'})_([\w\d\_]+[!?]?)}
18
19
 
19
20
  def method_missing(method, *args, &block)
20
21
  if match = (meth = method.to_s).match(RMTools::Iterators)
@@ -15,26 +15,26 @@ module RMTools
15
15
  end
16
16
  end
17
17
 
18
- ANSI2UTF = Cyrillic::ANSI2UTF = Iconv.new("UTF-8", "WINDOWS-1251").method(:iconv)
19
- UTF2ANSI = Cyrillic::UTF2ANSI = Iconv.new("WINDOWS-1251", "UTF-8").method(:iconv)
18
+ ANSI2UTF = Cyrillic::ANSI2UTF = Iconv.new("UTF-8//IGNORE", "WINDOWS-1251//IGNORE").method(:iconv)
19
+ UTF2ANSI = Cyrillic::UTF2ANSI = Iconv.new("WINDOWS-1251//IGNORE", "UTF-8//IGNORE").method(:iconv)
20
20
  ICONVS = {}
21
21
  end
22
22
 
23
23
  class String
24
24
 
25
- def utf(from_encoding='WINDOWS-1251')
26
- (ICONVS['UTF-8<'+from_encoding] ||= Iconv.new('UTF-8', from_encoding)).iconv(self)
25
+ def utf(from_encoding='WINDOWS-1251//IGNORE')
26
+ (ICONVS['UTF-8<'+from_encoding] ||= Iconv.new('UTF-8//IGNORE', from_encoding)).iconv(self)
27
27
  end
28
28
 
29
- def ansi(from_encoding='UTF-8')
30
- (ICONVS['WINDOWS-1251<'+from_encoding] ||= Iconv.new('WINDOWS-1251', from_encoding)).iconv(self)
29
+ def ansi(from_encoding='UTF-8//IGNORE')
30
+ (ICONVS['WINDOWS-1251<'+from_encoding] ||= Iconv.new('WINDOWS-1251//IGNORE', from_encoding)).iconv(self)
31
31
  end
32
32
 
33
- def utf!(from_encoding='WINDOWS-1251')
33
+ def utf!(from_encoding='WINDOWS-1251//IGNORE')
34
34
  replace utf from_encoding
35
35
  end
36
36
 
37
- def ansi!(from_encoding='UTF-8')
37
+ def ansi!(from_encoding='UTF-8//IGNORE')
38
38
  replace ansi from_encoding
39
39
  end
40
40
 
@@ -2,23 +2,59 @@
2
2
  RMTools::require 'lang/ansi'
3
3
 
4
4
  class String
5
+ XML_CHARSET_RE = /(?:encoding|charset)=(.+?)"/
5
6
 
6
- def xml_charset
7
- charset = (charset = self[0,2000].match(/(?:encoding|charset)=(.+?)"/)) ?
8
- charset[1].upcase : 'UTF8'
9
- if charset and charset != 'UTF-8'
10
- utf!(charset) rescue(charset = nil)
7
+ if RUBY_VERSION < '1.9'
8
+
9
+ def xml_charset
10
+ charset = (charset = self[0,2000].match(XML_CHARSET_RE)) ?
11
+ charset[1].upcase : 'UTF8'
12
+ if charset and charset != 'UTF-8'
13
+ utf!(charset) rescue(charset = nil)
14
+ end
15
+ charset
11
16
  end
12
- charset
13
- end
14
-
15
- def xml_to_utf
16
- charset = (charset = self[0,2000].match(/(?:encoding|charset)=(.+?)"/)) ?
17
- charset[1].upcase : 'UTF8'
18
- if charset and charset != 'UTF-8'
19
- utf!(charset) rescue()
17
+
18
+ def xml_to_utf
19
+ charset = (charset = self[0,2000].match(XML_CHARSET_RE)) ?
20
+ charset[1].upcase : 'UTF8'
21
+ if charset and charset != 'UTF-8'
22
+ utf!(charset) rescue()
23
+ end
24
+ self
25
+ end
26
+
27
+ else
28
+
29
+ def xml_charset
30
+ ss = StringScanner(self)
31
+ if ss.scan_until(XML_CHARSET_RE)
32
+ charset = ss.matched.match(XML_CHARSET_RE)[1]
33
+ if charset != 'UTF-8'
34
+ utf!(charset) rescue(charset = nil)
35
+ charset
36
+ end
37
+ end
38
+ end
39
+
40
+ def xml_to_utf
41
+ if encoding.name == 'UTF-8'
42
+ self
43
+ elsif xcs = xml_charset
44
+ if xcs != 'UTF-8'
45
+ begin
46
+ utf! xcs
47
+ rescue
48
+ force_encoding 'UTF-8'
49
+ end
50
+ else
51
+ self
52
+ end
53
+ else
54
+ force_encoding 'UTF-8'
55
+ end
20
56
  end
21
- self
57
+
22
58
  end
23
59
 
24
60
  def to_doc(forceutf=nil)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.11
4
+ version: 1.2.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-07 00:00:00.000000000 Z
12
+ date: 2013-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake