rmtools 2.2.7 → 2.3.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/ext/rmtools.h CHANGED
@@ -1,162 +1,162 @@
1
- #ifndef __RUBY_INTERNALS_HH__
2
- #define __RUBY_INTERNALS_HH__
3
-
4
- #include <ruby.h>
5
-
6
- #ifdef RUBY_IS_19
7
-
8
- #include <ruby/intern.h>
9
- #include <ruby/defines.h>
10
- #include <ruby/re.h>
11
- #include <assert.h>
12
-
13
- # define ARY_EMBED_P(ary) \
14
- (assert(!FL_TEST(ary, ELTS_SHARED) || !FL_TEST(ary, RARRAY_EMBED_FLAG)), \
15
- FL_TEST(ary, RARRAY_EMBED_FLAG))
16
- #define ARY_SET_EMBED_LEN(ary, n) do { \
17
- long tmp_n = n; \
18
- RBASIC(ary)->flags &= ~RARRAY_EMBED_LEN_MASK; \
19
- RBASIC(ary)->flags |= (tmp_n) << RARRAY_EMBED_LEN_SHIFT; \
20
- } while (0)
21
- #define ARY_SET_HEAP_LEN(ary, n) do { \
22
- RARRAY(ary)->as.heap.len = n; \
23
- } while (0)
24
- #define ARY_SET_LEN(ary, n) do { \
25
- if (ARY_EMBED_P(ary)) { \
26
- ARY_SET_EMBED_LEN(ary, n); \
27
- } \
28
- else { \
29
- ARY_SET_HEAP_LEN(ary, n); \
30
- } \
31
- } while (0)
32
-
33
- #define BDIGITS(x) ((BDIGIT*)RBIGNUM_DIGITS(x))
34
-
35
- // copied from utilrb gem
36
- typedef struct RNode {
37
- unsigned long flags;
38
- char *nd_file;
39
- union {
40
- struct RNode *node;
41
- ID id;
42
- VALUE value;
43
- VALUE (*cfunc)(ANYARGS);
44
- ID *tbl;
45
- } u1;
46
- union {
47
- struct RNode *node;
48
- ID id;
49
- long argc;
50
- VALUE value;
51
- } u2;
52
- union {
53
- struct RNode *node;
54
- ID id;
55
- long state;
56
- struct global_entry *entry;
57
- long cnt;
58
- VALUE value;
59
- } u3;
60
- } NODE;
61
-
62
- typedef struct RVALUE {
63
- union {
64
- struct {
65
- VALUE flags; /* always 0 for freed obj */
66
- struct RVALUE *next;
67
- } free;
68
- struct RBasic basic;
69
- struct RObject object;
70
- struct RClass klass;
71
- struct RFloat flonum;
72
- struct RString string;
73
- struct RArray array;
74
- struct RRegexp regexp;
75
- struct RHash hash;
76
- struct RData data;
77
- struct RStruct rstruct;
78
- struct RBignum bignum;
79
- struct RFile file;
80
- struct RNode node;
81
- struct RMatch match;
82
- struct RRational rational;
83
- struct RComplex complex;
84
- } as;
85
- } RVALUE;
86
-
87
- static const size_t SLOT_SIZE = sizeof(RVALUE);
88
-
89
- #else
90
-
91
- #include <intern.h>
92
- #include <node.h>
93
- #include <env.h>
94
- #include <re.h>
95
-
96
- # define STR_SET_LEN(x, i) (RSTRING(x)->len = (i))
97
-
98
- #ifndef RFLOAT_VALUE
99
- # define RFLOAT_VALUE(f) (RFLOAT(f)->value)
100
- # define RBIGNUM_DIGITS(f) (RBIGNUM(f)->digits)
101
- # define RBIGNUM_LEN(f) (RBIGNUM(f)->len)
102
- #endif
103
-
104
- # define ARY_SET_LEN(x, i) (RARRAY(x)->len = (i))
105
-
106
- # define BDIGITS(x) ((BDIGIT*)RBIGNUM(x)->digits)
107
-
108
- // copied from utilrb gem
109
- typedef struct RVALUE {
110
- union {
111
- struct {
112
- unsigned long flags; /* always 0 for freed obj */
113
- struct RVALUE *next;
114
- } free;
115
- struct RBasic basic;
116
- struct RObject object;
117
- struct RClass klass;
118
- struct RFloat flonum;
119
- struct RString string;
120
- struct RArray array;
121
- struct RRegexp regexp;
122
- struct RHash hash;
123
- struct RData data;
124
- struct RStruct rstruct;
125
- struct RBignum bignum;
126
- struct RFile file;
127
- struct RNode node;
128
- struct RMatch match;
129
- struct RVarmap varmap;
130
- struct SCOPE scope;
131
- } as;
132
- #ifdef GC_DEBUG
133
- char *file;
134
- int line;
135
- #endif
136
- } RVALUE;
137
- static const size_t SLOT_SIZE = sizeof(RVALUE);
138
-
139
-
140
- #endif // 1.9
141
-
142
-
143
-
144
- // shortcuts for debug r_r
145
- extern void rb_log(const char* str)
146
- {
147
- rb_funcall(rb_gv_get("$log"), rb_intern("debug"), 1, rb_str_new2(str));
148
- }
149
- extern void rb_log_obj(VALUE obj)
150
- {
151
- rb_funcall(rb_gv_get("$log"), rb_intern("debug"), 1, obj);
152
- }
153
- extern void rb_log_file(const char* str)
154
- {
155
- rb_funcall(rb_gv_get("$log"), rb_intern("log"), 1, rb_str_new2(str));
156
- }
157
- extern void rb_log_file_obj(VALUE obj)
158
- {
159
- rb_funcall(rb_gv_get("$log"), rb_intern("log"), 1, obj);
160
- }
161
-
1
+ #ifndef __RUBY_INTERNALS_HH__
2
+ #define __RUBY_INTERNALS_HH__
3
+
4
+ #include <ruby.h>
5
+
6
+ #ifdef RUBY_IS_19
7
+
8
+ #include <ruby/intern.h>
9
+ #include <ruby/defines.h>
10
+ #include <ruby/re.h>
11
+ #include <assert.h>
12
+
13
+ # define ARY_EMBED_P(ary) \
14
+ (assert(!FL_TEST(ary, ELTS_SHARED) || !FL_TEST(ary, RARRAY_EMBED_FLAG)), \
15
+ FL_TEST(ary, RARRAY_EMBED_FLAG))
16
+ #define ARY_SET_EMBED_LEN(ary, n) do { \
17
+ long tmp_n = n; \
18
+ RBASIC(ary)->flags &= ~RARRAY_EMBED_LEN_MASK; \
19
+ RBASIC(ary)->flags |= (tmp_n) << RARRAY_EMBED_LEN_SHIFT; \
20
+ } while (0)
21
+ #define ARY_SET_HEAP_LEN(ary, n) do { \
22
+ RARRAY(ary)->as.heap.len = n; \
23
+ } while (0)
24
+ #define ARY_SET_LEN(ary, n) do { \
25
+ if (ARY_EMBED_P(ary)) { \
26
+ ARY_SET_EMBED_LEN(ary, n); \
27
+ } \
28
+ else { \
29
+ ARY_SET_HEAP_LEN(ary, n); \
30
+ } \
31
+ } while (0)
32
+
33
+ #define BDIGITS(x) ((BDIGIT*)RBIGNUM_DIGITS(x))
34
+
35
+ // copied from utilrb gem
36
+ typedef struct RNode {
37
+ unsigned long flags;
38
+ char *nd_file;
39
+ union {
40
+ struct RNode *node;
41
+ ID id;
42
+ VALUE value;
43
+ VALUE (*cfunc)(ANYARGS);
44
+ ID *tbl;
45
+ } u1;
46
+ union {
47
+ struct RNode *node;
48
+ ID id;
49
+ long argc;
50
+ VALUE value;
51
+ } u2;
52
+ union {
53
+ struct RNode *node;
54
+ ID id;
55
+ long state;
56
+ struct global_entry *entry;
57
+ long cnt;
58
+ VALUE value;
59
+ } u3;
60
+ } NODE;
61
+
62
+ typedef struct RVALUE {
63
+ union {
64
+ struct {
65
+ VALUE flags; /* always 0 for freed obj */
66
+ struct RVALUE *next;
67
+ } free;
68
+ struct RBasic basic;
69
+ struct RObject object;
70
+ struct RClass klass;
71
+ struct RFloat flonum;
72
+ struct RString string;
73
+ struct RArray array;
74
+ struct RRegexp regexp;
75
+ struct RHash hash;
76
+ struct RData data;
77
+ struct RStruct rstruct;
78
+ struct RBignum bignum;
79
+ struct RFile file;
80
+ struct RNode node;
81
+ struct RMatch match;
82
+ struct RRational rational;
83
+ struct RComplex complex;
84
+ } as;
85
+ } RVALUE;
86
+
87
+ static const size_t SLOT_SIZE = sizeof(RVALUE);
88
+
89
+ #else
90
+
91
+ #include <intern.h>
92
+ #include <node.h>
93
+ #include <env.h>
94
+ #include <re.h>
95
+
96
+ # define STR_SET_LEN(x, i) (RSTRING(x)->len = (i))
97
+
98
+ #ifndef RFLOAT_VALUE
99
+ # define RFLOAT_VALUE(f) (RFLOAT(f)->value)
100
+ # define RBIGNUM_DIGITS(f) (RBIGNUM(f)->digits)
101
+ # define RBIGNUM_LEN(f) (RBIGNUM(f)->len)
102
+ #endif
103
+
104
+ # define ARY_SET_LEN(x, i) (RARRAY(x)->len = (i))
105
+
106
+ # define BDIGITS(x) ((BDIGIT*)RBIGNUM(x)->digits)
107
+
108
+ // copied from utilrb gem
109
+ typedef struct RVALUE {
110
+ union {
111
+ struct {
112
+ unsigned long flags; /* always 0 for freed obj */
113
+ struct RVALUE *next;
114
+ } free;
115
+ struct RBasic basic;
116
+ struct RObject object;
117
+ struct RClass klass;
118
+ struct RFloat flonum;
119
+ struct RString string;
120
+ struct RArray array;
121
+ struct RRegexp regexp;
122
+ struct RHash hash;
123
+ struct RData data;
124
+ struct RStruct rstruct;
125
+ struct RBignum bignum;
126
+ struct RFile file;
127
+ struct RNode node;
128
+ struct RMatch match;
129
+ struct RVarmap varmap;
130
+ struct SCOPE scope;
131
+ } as;
132
+ #ifdef GC_DEBUG
133
+ char *file;
134
+ int line;
135
+ #endif
136
+ } RVALUE;
137
+ static const size_t SLOT_SIZE = sizeof(RVALUE);
138
+
139
+
140
+ #endif // 1.9
141
+
142
+
143
+
144
+ // shortcuts for debug r_r
145
+ extern void rb_log(const char* str)
146
+ {
147
+ rb_funcall(rb_gv_get("$log"), rb_intern("debug"), 1, rb_str_new2(str));
148
+ }
149
+ extern void rb_log_obj(VALUE obj)
150
+ {
151
+ rb_funcall(rb_gv_get("$log"), rb_intern("debug"), 1, obj);
152
+ }
153
+ extern void rb_log_file(const char* str)
154
+ {
155
+ rb_funcall(rb_gv_get("$log"), rb_intern("log"), 1, rb_str_new2(str));
156
+ }
157
+ extern void rb_log_file_obj(VALUE obj)
158
+ {
159
+ rb_funcall(rb_gv_get("$log"), rb_intern("log"), 1, obj);
160
+ }
161
+
162
162
  #endif
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rmtools/core/object'
3
-
4
2
  class Class
5
3
 
6
4
  def method_proxy *vars
@@ -20,8 +20,12 @@ module RMTools
20
20
  # >> 10/0 end
21
21
  # from (irb):3
22
22
  # >> divbyzero
23
-
24
- IgnoreFiles = %r{#{Regexp.escape $:.grep(%r{/ruby/1\.(8|9\.\d)$})[0]}/irb(/|\.rb$)|/active_support/dependencies.rb$}
23
+
24
+ if RUBY_VERSION < '2'
25
+ IgnoreFiles = %r{#{Regexp.escape $:.grep(%r{/ruby/1\.(8|9\.\d)$})[0]}/irb(/|\.rb$)|/active_support/dependencies.rb$}
26
+ else
27
+ IgnoreFiles = %r{/irb(/|\.rb$)|/active_support/dependencies.rb$}
28
+ end
25
29
 
26
30
  def format_trace(a)
27
31
  return [] if !a.b
@@ -117,7 +117,7 @@ module RMTools
117
117
  cmd = "scp #{fullpath.inspect} #{[@host, fpath].join(':').inspect} 2>&1"
118
118
  print "`#{cmd}`: " if @debug
119
119
  if res = RMTools::tick_while {`#{cmd}`}.b
120
- puts "[ #{Painter.r_b('Error')} ]: #{res}"
120
+ puts "[ #{Painter.rb('Error')} ]: #{res}"
121
121
  else
122
122
  print "[ #{Painter.g('OK')} ]"
123
123
  end
@@ -73,9 +73,5 @@ end
73
73
  def truth_map
74
74
  map_values {|v| !!v}
75
75
  end
76
-
77
- def key_value
78
- to_a.first
79
- end
80
76
 
81
77
  end
@@ -14,8 +14,7 @@ module RMTools
14
14
  alias :coallition :+
15
15
  alias :subtraction :-
16
16
  alias :intersection :&
17
- # :& won't work this way if :intersection will be protected
18
- protected :union, :coallition, :subtraction
17
+ protected :union, :coallition, :subtraction, :intersection
19
18
 
20
19
  def |(ary)
21
20
  return ary.uniq if empty?
@@ -56,17 +55,12 @@ module RMTools
56
55
  [self - common, ary - common]
57
56
  end
58
57
 
59
- alias :diff :^
58
+ alias diff ^
60
59
 
61
60
  def intersects?(ary)
62
61
  (self & ary).any?
63
62
  end
64
63
  alias :x? :intersects?
65
-
66
- def =~(ary)
67
- (self - ary).empty?
68
- end
69
- alias :is_subset_of? :=~
70
64
  }
71
65
  super
72
66
  end
@@ -1,6 +1,8 @@
1
1
  # encoding: utf-8
2
- require 'iconv'
3
- # Although ruby >= 1.9.3 would complain about not using String#encode, iconv is 2-4 times faster and still handles the ruby string encoding
2
+ if RUBY_VERSION < '2'
3
+ # Although ruby >= 1.9.3 would complain about not using String#encode, iconv is 2-4 times faster and still handles the ruby string encoding
4
+ require 'iconv'
5
+ end
4
6
 
5
7
  module RMTools
6
8
  ENCODINGS_PATTERNS = {}
@@ -17,48 +19,81 @@ module RMTools
17
19
  ANSI_ENCODING = ANSI_LETTERS_UC[0].encoding
18
20
  end
19
21
 
20
- ENCODINGS_PATTERNS["WINDOWS-1251"] = /[#{ANSI_LETTERS_UC.join}]/
22
+ ENCODINGS_PATTERNS["WINDOWS-1251"] = /[#{ANSI_LETTERS_UC.concat(ANSI_YOYE).join}]/
21
23
  end
22
24
 
23
- ICONVS = {}
24
- ANSI2UTF = Cyrillic::ANSI2UTF = Iconv.new("UTF-8//IGNORE", "WINDOWS-1251//IGNORE").method(:iconv)
25
- UTF2ANSI = Cyrillic::UTF2ANSI = Iconv.new("WINDOWS-1251//IGNORE", "UTF-8//IGNORE").method(:iconv)
25
+ if RUBY_VERSION < '2'
26
+ ICONVS = {}
27
+ ANSI2UTF = Cyrillic::ANSI2UTF = Iconv.new("UTF-8//IGNORE", "WINDOWS-1251//IGNORE").method(:iconv)
28
+ UTF2ANSI = Cyrillic::UTF2ANSI = Iconv.new("WINDOWS-1251//IGNORE", "UTF-8//IGNORE").method(:iconv)
29
+ else
30
+ ANSI2UTF = Cyrillic::ANSI2UTF = lambda {|str|
31
+ str.encode("WINDOWS-1251", :invalid => :replace, :undef => :replace, :replace => "").encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "")
32
+ }
33
+ UTF2ANSI = Cyrillic::UTF2ANSI = lambda {|str|
34
+ str.encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "").encode("WINDOWS-1251", :invalid => :replace, :undef => :replace, :replace => "")
35
+ }
36
+ end
26
37
  end
27
38
 
28
39
  class String
29
40
 
30
- def utf(from_encoding="#{encoding.name.upcase}//IGNORE")
31
- (ICONVS['UTF-8<'+from_encoding] ||= Iconv.new('UTF-8//IGNORE', from_encoding)).iconv(self)
32
- end
33
-
34
- def ansi(from_encoding="#{encoding.name.upcase}//IGNORE")
35
- (ICONVS['WINDOWS-1251<'+from_encoding] ||= Iconv.new('WINDOWS-1251//IGNORE', from_encoding)).iconv(self)
36
- end
37
-
38
- def utf!(from_encoding="#{encoding.name.upcase}//IGNORE")
39
- replace utf from_encoding
40
- end
41
-
42
- def ansi!(from_encoding="#{encoding.name.upcase}//IGNORE")
43
- replace ansi from_encoding
41
+ if RUBY_VERSION < '2'
42
+
43
+ def utf(from_encoding='WINDOWS-1251//IGNORE')
44
+ (ICONVS['UTF-8<'+from_encoding] ||= Iconv.new('UTF-8//IGNORE', from_encoding)).iconv(self)
45
+ end
46
+
47
+ def ansi(from_encoding='UTF-8//IGNORE')
48
+ (ICONVS['WINDOWS-1251<'+from_encoding] ||= Iconv.new('WINDOWS-1251//IGNORE', from_encoding)).iconv(self)
49
+ end
50
+
51
+ def utf!(from_encoding='WINDOWS-1251//IGNORE')
52
+ replace utf from_encoding
53
+ end
54
+
55
+ def ansi!(from_encoding='UTF-8//IGNORE')
56
+ replace ansi from_encoding
57
+ end
58
+
59
+ else
60
+
61
+ def utf(from_encoding='WINDOWS-1251')
62
+ encode(from_encoding, :invalid => :replace, :undef => :replace, :replace => "").encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "")
63
+ end
64
+
65
+ def ansi(from_encoding='UTF-8')
66
+ encode(from_encoding, :invalid => :replace, :undef => :replace, :replace => "").encode("WINDOWS-1251", :invalid => :replace, :undef => :replace, :replace => "")
67
+ end
68
+
69
+ def utf!(from_encoding='WINDOWS-1251')
70
+ replace utf from_encoding
71
+ end
72
+
73
+ def ansi!(from_encoding='UTF-8')
74
+ replace ansi from_encoding
75
+ end
76
+
44
77
  end
45
78
 
46
79
 
47
- def utf?
80
+ def valid_encoding?
48
81
  begin
49
- encoding == Encoding::UTF_8 and self =~ /./u
50
- rescue Encoding::CompatibilityError
82
+ self =~ /./
83
+ rescue ArgumentError
51
84
  false
85
+ else
86
+ true
52
87
  end
53
88
  end
54
89
 
55
- def find_compatible_encoding
90
+ def fix_encoding!
56
91
  # UTF-8 by default
57
- return nil if utf?
92
+ return nil if valid_encoding?
58
93
  for enc, pattern in ENCODINGS_PATTERNS
59
94
  force_encoding(enc)
60
- if self =~ pattern
61
- return enc
95
+ if valid_encoding? and self =~ pattern
96
+ return encoding.name.upcase
62
97
  end
63
98
  end
64
99
  false
@@ -1,48 +1,96 @@
1
1
  # encoding: utf-8
2
2
  class String
3
+ if RUBY_VERSION < '1.9'
3
4
 
4
5
  def digit_date
5
- gsub(/jan|[яЯ][нН][вВ]([аА][рР][яЯьЬ]?)?/i, '01').
6
- gsub(/feb|[фФ][еЕ][вВ]([рР][аА][лЛ][яЯьЬ]?)?/i, '02').
7
- gsub(/mar|[мМ][аА][рР]([тТ][аА]?)?/i, '03').
8
- gsub(/apr|[аА][пП][рР]([еЕ][лЛ][яЯьЬ]?)?/i, '04').
9
- gsub(/may|[мМ][аА][яЯйЙ]?/i, '05').
6
+ gsub(/jan(?:uary)?|[яЯ][нН][вВ](?:[аА][рР][яЯьЬ]?)?/i, '01').
7
+ gsub(/feb(?:ruary)?|[фФ][еЕ][вВ](?:[рР][аА][лЛ][яЯьЬ]?)?/i, '02').
8
+ gsub(/mar(?:ch)?|[мМ][аА][рР](?:[тТ][аА]?)?/i, '03').
9
+ gsub(/apr(?:il)?|[аА][пП][рР](?:[еЕ][лЛ][яЯьЬ]?)?/i, '04').
10
+ gsub(/may|[мМ][аА][яЯйЙ]/i, '05').
10
11
  gsub(/june?|[иИ][юЮ][нН][яЯьЬ]?/i, '06').
11
12
  gsub(/july?|[иИ][юЮ][лЛ][яЯьЬ]?/i, '07').
12
- gsub(/aug|[аА][вВ][гГ]([уУ][сС][тТ][аА]?)?/i, '08').
13
- gsub(/sep|[сС][еЕ][нН]([тТ][яЯ][бБ][рР][яЯьЬ]?)?/i, '09').
14
- gsub(/oct|[оО][кК][тТ]([яЯ][бБ][рР][яЯьЬ]?)?/i, '10').
15
- gsub(/nov|[нН][оО][яЯ]([бБ][рР][яЯьЬ]?)?/i, '11').
16
- gsub(/dec|[дД][еЕ][кК]([аА][бБ][рР][яЯьЬ]?)?/i, '12')
13
+ gsub(/aug(?:ust)?|[аА][вВ][гГ](?:[уУ][сС][тТ][аА]?)?/i, '08').
14
+ gsub(/sep(?:tember)?|[сС][еЕ][нН](?:[тТ][яЯ][бБ][рР][яЯьЬ]?)?/i, '09').
15
+ gsub(/oct(?:ober)?|[оО][кК][тТ](?:[яЯ][бБ][рР][яЯьЬ]?)?/i, '10').
16
+ gsub(/nov(?:ember)?|[нН][оО][яЯ](?:[бБ][рР][яЯьЬ]?)?/i, '11').
17
+ gsub(/dec(?:ember)?|[дД][еЕ][кК](?:[аА][бБ][рР][яЯьЬ]?)?/i, '12')
17
18
  end
18
- alias :digitize :digit_date
19
19
 
20
20
  def tr_date
21
- gsub(/[яЯ][нН][вВ]([аА][рР][яЯьЬ]?)?/, 'jan').
22
- gsub(/[фФ][еЕ][вВ]([рР][аА][лЛ][яЯьЬ]?)?/, 'feb').
23
- gsub(/[мМ][аА][рР]([тТ][аА]?)?/, 'mar').
24
- gsub(/[аА][пП][рР]([еЕ][лЛ][яЯьЬ]?)?/, 'apr').
21
+ gsub(/[яЯ][нН][вВ](?:[аА][рР][яЯьЬ]?)?/, 'jan').
22
+ gsub(/[фФ][еЕ][вВ](?:[рР][аА][лЛ][яЯьЬ]?)?/, 'feb').
23
+ gsub(/[мМ][аА][рР](?:[тТ][аА]?)?/, 'mar').
24
+ gsub(/[аА][пП][рР](?:[еЕ][лЛ][яЯьЬ]?)?/, 'apr').
25
25
  gsub(/[мМ][аА][яЯйЙ]?/, 'may').
26
26
  gsub(/[иИ][юЮ][нН][яЯьЬ]?/, 'jun').
27
27
  gsub(/[иИ][юЮ][лЛ][яЯьЬ]?/, 'jul').
28
- gsub(/[аА][вВ][гГ]([уУ][сС][тТ][аА]?)?/, 'aug').
29
- gsub(/[сС][еЕ][нН]([тТ][яЯ][бБ][рР][яЯьЬ]?)?/, 'sep').
30
- gsub(/[оО][кК][тТ]([яЯ][бБ][рР][яЯьЬ]?)?/, 'oct').
31
- gsub(/[нН][оО][яЯ]([бБ][рР][яЯьЬ]?)?/, 'nov').
32
- gsub(/[дД][еЕ][кК]([аА][бБ][рР][яЯьЬ]?)?/, 'dec')
28
+ gsub(/[аА][вВ][гГ](?:[уУ][сС][тТ][аА]?)?/, 'aug').
29
+ gsub(/[сС][еЕ][нН](?:[тТ][яЯ][бБ][рР][яЯьЬ]?)?/, 'sep').
30
+ gsub(/[оО][кК][тТ](?:[яЯ][бБ][рР][яЯьЬ]?)?/, 'oct').
31
+ gsub(/[нН][оО][яЯ](?:[бБ][рР][яЯьЬ]?)?/, 'nov').
32
+ gsub(/[дД][еЕ][кК](?:[аА][бБ][рР][яЯьЬ]?)?/, 'dec')
33
33
  end
34
34
 
35
35
  def digit_nums
36
36
  gsub(/[оО][дД][иИ][нН]|[еЕ][дД][иИ][нН][иИ][цЦ][аА]/, '1').
37
- gsub(/[дД][вВ]([оО][йЙ][кК])?[аА]/, '2').
38
- gsub(/[тТ][рР]([иИ]|[оО][йЙ][кК][аА])/, '3').
39
- gsub(/[чЧ][еЕ][тТ]([ыЫ][рР][еЕ]|[вВ][еЕёЁ][рР][кК][аА])/, '4').
40
- gsub(/[пП][яЯ][тТ]([ьЬ]|[еЕёЁ][рР][кК][аА])/, '5').
41
- gsub(/[шШ][еЕ][сС][тТ]([ьЬ]|[еЕёЁ][рР][кК][аА])/, '6').
42
- gsub(/[сС][еЕ][мМ]([ьЬ]|[еЕёЁ][рР][кК][аА])/, '7').
43
- gsub(/[вВ][оО][сС]([еЕ][мМ][ьЬ]|[ьЬ][мМ][еЕёЁ][рР][кК][аА])/i, '8').
44
- gsub(/[дД][еЕ][вВ][яЯ][тТ]([ьЬ]|[кК][аА])/, '9').
37
+ gsub(/[дД][вВ](?:[оО][йЙ][кК])?[аА]/, '2').
38
+ gsub(/[тТ][рР](?:[иИ]|[оО][йЙ][кК][аА])/, '3').
39
+ gsub(/[чЧ][еЕ][тТ](?:[ыЫ][рР][еЕ]|[вВ][еЕёЁ][рР][кК][аА])/, '4').
40
+ gsub(/[пП][яЯ][тТ](?:[ьЬ]|[еЕёЁ][рР][кК][аА])/, '5').
41
+ gsub(/[шШ][еЕ][сС][тТ](?:[ьЬ]|[еЕёЁ][рР][кК][аА])/, '6').
42
+ gsub(/[сС][еЕ][мМ](?:[ьЬ]|[еЕёЁ][рР][кК][аА])/, '7').
43
+ gsub(/[вВ][оО][сС](?:[еЕ][мМ][ьЬ]|[ьЬ][мМ][еЕёЁ][рР][кК][аА])/i, '8').
44
+ gsub(/[дД][еЕ][вВ][яЯ][тТ](?:[ьЬ]|[кК][аА])/, '9').
45
45
  gsub(/[нН][оОуУ][лЛ][ьЬ]/, '0')
46
46
  end
47
-
47
+
48
+ else
49
+
50
+ def digit_date
51
+ gsub(/jan(?:uary)?|янв(?:ар[яь])?/i, '01').
52
+ gsub(/feb(?:ruary)?|фев(?:рал[яь])?/i, '02').
53
+ gsub(/mar(?:ch)?|март?а?/i, '03').
54
+ gsub(/apr(?:il)?|апр(?:ел[яь])?/i, '04').
55
+ gsub(/may|ма[яй]/i, '05').
56
+ gsub(/june?|июн[яь]?/i, '06').
57
+ gsub(/july?|июл[яь]?/i, '07').
58
+ gsub(/aug(?:ust)?|авг(?:уста?)?/i, '08').
59
+ gsub(/sep(?:tember)?|сен(?:тябр[яь])?/i, '09').
60
+ gsub(/oct(?:ober)?|окт(?:ябр[яь])?/i, '10').
61
+ gsub(/nov(?:ember)?|ноя(?:бр[яь])?/i, '11').
62
+ gsub(/dec(?:ember)?|дек(?:абр[яь])?/i, '12')
63
+ end
64
+
65
+ def tr_date
66
+ gsub(/янв(?:ар[яь])?/i, 'jan').
67
+ gsub(/фев(?:рал[яь])?/i, 'feb').
68
+ gsub(/март?а?/i, 'mar').
69
+ gsub(/апр(?:ел[яь])?/i, 'apr').
70
+ gsub(/ма[яй]/i, 'may').
71
+ gsub(/июн[яь]?/i, 'jun').
72
+ gsub(/июл[яь]?/i, 'jul').
73
+ gsub(/авг(?:уста?)?/i, 'aug').
74
+ gsub(/сен(?:тябр[яь])?/i, 'sep').
75
+ gsub(/окт(?:ябр[яь])?/i, 'oct').
76
+ gsub(/ноя(?:бр[яь])?/i, 'nov').
77
+ gsub(/дек(?:абр[яь])?/i, 'dec')
78
+ end
79
+
80
+ def digit_nums
81
+ gsub(/один|единица/i, '1').
82
+ gsub(/дв(?:ойк|а)/i, '2').
83
+ gsub(/тр(и|ойка)/i, '3').
84
+ gsub(/чет(?:ыре|в[её]рка)/i, '4').
85
+ gsub(/пят(?:ь|[её]рка)/i, '5').
86
+ gsub(/шест(?:ь|[её]рка)/, '6').
87
+ gsub(/сем(?:ь|[её]рка)/i, '7').
88
+ gsub(/вос(?:емь|ьм[её]рка)/i, '8').
89
+ gsub(/девят(ь|ка)/i, '9').
90
+ gsub(/н[оу]ль/i, '0')
91
+ end
92
+
93
+ end
94
+
95
+ alias :digitize :digit_date
48
96
  end
@@ -1,3 +1,3 @@
1
1
  module RMTools
2
- VERSION = '2.2.7'
2
+ VERSION = '2.3.0'
3
3
  end
data/rmtools.gemspec CHANGED
@@ -19,9 +19,11 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_runtime_dependency "activesupport"
22
+ if RUBY_VERSION < '2'
22
23
  #unless ext_files_not_modified 'rmtools', RMTools::VERSION
23
24
  spec.extensions << 'ext/extconf.rb'
24
25
  #end
26
+ end
25
27
 
26
28
  spec.add_development_dependency "bundler", "~> 1.3"
27
29
  spec.add_development_dependency "rake"