rdoba 0.9 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 000e2b10a8728464889da9e1fb18cb1dc12593a6
4
- data.tar.gz: 9e5d1e6da0d62943247e5158305f87b93016825a
5
- SHA512:
6
- metadata.gz: e4b93ed652786a11219857fe012041695722bc23c9fa2560060e40e0e4b56af4b1eab8862b085eb0bca492b6807342f3b489cae1795d9908722b6f88bdc7b3fe
7
- data.tar.gz: e04e6fddfd18f48c00b0335a6cdab61106e5428bbfa5e31ba54920be388f027a192d65c16b14c18d9d4880ef54da8c4cbef54470d1f36858a7a2126ef5ba4375
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 42b106c41e5273c7b2d1594996b557121eb37663
4
+ data.tar.gz: 6eefdf94d3d1dbc3f1aaafa054a2ff2e46bf2bc9
5
+ SHA512:
6
+ metadata.gz: e9f284c473161858b14946754204530adae45f8f565716b03a192cb2a5c6ec0dbb319516effb2515e12766ae24a637491e06fae97cbb4824fb4a51327f9f5d30
7
+ data.tar.gz: 5167bd2b03969c63fd0412a11e76c649c41702a67f5143184ca79c6f545196ab57401688248c52d4a0446a8a264fefbd84796dfefc74eafa42d3988afd5f78e7
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ tmp
19
19
  *.swp
20
20
  *~
21
21
  .rvmrc
22
+ .coveralls.yml
data/README.md CHANGED
@@ -1,10 +1,20 @@
1
1
  # Rdoba
2
+ <!---
3
+ ![Web Component Logo](http://??.tinypic.com/??.png)
4
+ -->
5
+ [![Gem Version](https://badge.fury.io/rb/rdoba.png)](http://rubygems.org/gems/rdoba)
6
+ [![Build Status](https://travis-ci.org/3aHyga/rdoba.png?branch=master)](https://travis-ci.org/3aHyga/rdoba)
7
+ [![Coverage Status](https://coveralls.io/repos/3aHyga/rdoba/badge.png)](https://coveralls.io/r/3aHyga/rdoba)
8
+ [![Code Climate](https://codeclimate.com/github/3aHyga/rdoba.png)](https://codeclimate.com/github/3aHyga/rdoba)
9
+ [![Endorse Count](http://api.coderwall.com/3aHyga/endorsecount.png)](http://coderwall.com/3aHyga)
2
10
 
3
11
  Rdoba, сирѣчь руби-добавокъ, есть библиотека, расширитяющая основныя классы Ruby такія какъ: Объектъ(Object), Ядро(Kernel), Строка(String), Словарь(Hash), Наборъ(Array), Пущь(NilClass) и т.д. Включаетъ модули и такія функціи:
4
12
  * common - нѣкоторыя простыя методы къ Объекту, Ядру, Пущю, Набору, Строкѣ и Словрю;
5
13
  * a - чтеніе и запись значеній въ Наборъ и Словарь по индексу;
6
14
  * combinations - перечисленіе значеній Набора въ различномъ порядкѣ;
7
15
  * log - функціи сборки отладочныхъ свѣдѣній приложенія;
16
+ * gem - нѣкоторыя методы бисера Rdoba, въ частности определенія оси и корневой папки бисера;
17
+ * mixin - примѣси, которыя могутъ быть подмѣшаны въ основныя классы рубинки;
8
18
  * dup - функціи удвоенія Словаря и Набораъ, включая ихъ вложенія;
9
19
  * hashorder - перечисленіе значеній Словаря въ заданномъ порядкѣ;
10
20
  * numeric - разширенный переводъ числа въ строку и строки въ число;
@@ -85,6 +95,53 @@ Rdoba, сирѣчь руби-добавокъ, есть библиотека, р
85
95
 
86
96
  A.new # » This is the Log
87
97
 
98
+
99
+ ### Методы бисера Rdoba
100
+ #### Rdoba.os
101
+ Методъ возвращаетъ видъ оси, на которой былъ запущенъ руби.
102
+
103
+ require 'rdoba'
104
+
105
+ Rdoba.os # » "linux"
106
+
107
+ #### Rdoba.gemroot
108
+ Методъ принимаетъ на входѣ параметръ имени бисера, и возвращаетъ корневую папку онаго бисера.
109
+
110
+ require 'rdoba'
111
+
112
+ Rdoba.gemroot 'rdoba' # » "/home/malo/git/rdoba"
113
+
114
+ ### Методы бисера Rdoba
115
+ Модуль содержитъ примѣсныя методы, которыя могутъ быть подмѣшаны въ основныя классы рубинки.
116
+
117
+ ### Пусто ли? (Is it empty?)
118
+ Проверяет пуста ли переменная.
119
+
120
+ require 'rdoba'
121
+ rdoba :mixin => [ :empty ]
122
+ nil.empty? # » true
123
+ false.empty? # » false
124
+ Object.new.empty? # » false
125
+
126
+ ### Пречинение Набора в Словарь (Array to Hash)
127
+ Преобразуетъ Набор в Словарь по определённымъ правиламъ.
128
+
129
+ require 'rdoba'
130
+ rdoba :mixin => [ :to_h ]
131
+ [ 'aa', 0,
132
+ 'bb', 1 ].to_h # » {"aa"=>nil, 0=>nil, "bb"=>nil, 1=>nil
133
+ [ [ 'aa', 0, ],
134
+ [ 'bb', 1 ] ].to_h # » {"aa"=>0, "bb"=>1}
135
+ [ [ 'aa', 0, 1, ],
136
+ [ 'bb', [ 1, 0 ] ] ].to_h # » {"aa"=>[0, 1], "bb"=>[1, 0]}
137
+ [ [ 'aa', 0, ],
138
+ [ 'aa', 1 ] ].to_h # » {"aa"=>[0, 1]}
139
+ [ [ 'aa', 0, ],
140
+ [ 'aa', 0 ] ].to_h # » {"aa"=>[0, 1]}
141
+ [ [ 'aa', 0, ],
142
+ [ 'aa', 0 ] ].to_h( :save_unique => true ) # » {"aa"=>[0]}
143
+
144
+
88
145
  ### Одвоеніе Словаря и Набора
89
146
 
90
147
  Позволяетъ выполнять какъ обычное, такъ и вложенное одвоеніе Словаря или Набора.
@@ -107,7 +164,7 @@ Rdoba, сирѣчь руби-добавокъ, есть библиотека, р
107
164
 
108
165
  ### Перечисленіе значеній Словаря въ заданномъ порядкѣ
109
166
 
110
- Позволядетъ перебрать всѣ ключи и значенія Словаря по опредѣлённому порядку. Порядок сей задаётся свойствомъ Словаря :order. Если въ заданном порядкѣ не всѣ ключи опредѣлены, то сначала перебираются заданныя ключ, а затѣмъ уже остальныя въ порядкѣ какъ они заданы въ Словарѣ. Перебирать можно ключи, пары или значенія по ключамъ. 4 метода суть перебора: each, each_pair, each_key, each_value. Удаляется порядокъ методом disorder.
167
+ Позволяетъ перебрать всѣ ключи и значенія Словаря по опредѣлённому порядку. Порядок сей задаётся свойствомъ Словаря :order. Если въ заданном порядкѣ не всѣ ключи опредѣлены, то сначала перебираются заданныя ключ, а затѣмъ уже остальныя въ порядкѣ какъ они заданы въ Словарѣ. Перебирать можно ключи, пары или значенія по ключамъ. 4 метода суть перебора: each, each_pair, each_key, each_value. Удаляется порядокъ методом disorder.
111
168
 
112
169
  require 'rdoba/hashorder'
113
170
 
data/Rakefile CHANGED
@@ -1,18 +1,37 @@
1
1
  #!/usr/bin/env rake
2
2
 
3
3
  desc "Prepare bundler"
4
- task :prebundle do
4
+ task :bundleup do
5
5
  sh 'gem install bundler --version "~> 1.3.1" --no-ri --no-rdoc'
6
6
  end
7
7
 
8
+ desc "Requires"
9
+ task :req do
10
+ $: << File.expand_path( '../lib', __FILE__ )
11
+ require 'bundler/gem_helper'
12
+
13
+ Bundler::GemHelper.install_tasks
14
+ end
15
+
8
16
  desc "Prepare bundle environment"
9
- task :pre do
17
+ task :up do
10
18
  sh 'bundle install'
11
19
  end
12
20
 
21
+ desc "Test with cucumber"
22
+ task :test do
23
+ sh 'cucumber features/log.feature features/bcd.feature'
24
+ end
25
+
26
+ desc "Distilled clean"
27
+ task :distclean do
28
+ sh 'git clean -fd'
29
+ sh 'cat .gitignore | while read mask; do rm -rf $(find -iname "$mask"); done'
30
+ end
31
+
13
32
  desc "Generate gem"
14
33
  namespace :gem do
15
- task :build do
34
+ task :build => [ :req ] do
16
35
  sh 'gem build rdoba.gemspec'
17
36
  end
18
37
 
@@ -21,7 +40,7 @@ namespace :gem do
21
40
  sh "gem install rdoba-#{Rdoba::VERSION}.gem"
22
41
  end
23
42
 
24
- task :publish do
43
+ task :publish => [ :req ] do
25
44
  require File.expand_path( '../lib/rdoba/_version_', __FILE__ )
26
45
  sh "git tag v#{Rdoba::VERSION}"
27
46
  sh "git push"
@@ -34,5 +53,6 @@ namespace :gem do
34
53
  end
35
54
 
36
55
  task(:default).clear
37
- task :default => :pre
38
- task :all => [ :prebundle, :pre ]
56
+ task :default => :test
57
+ task :all => [ :bundleup, :up, :test, :'gem:make', :distclean ]
58
+ task :build => [ :bundleup, :up, :test, :'gem:build', :'gem:install', :distclean ]
@@ -1,6 +1,8 @@
1
1
  require 'rdoba'
2
2
  require 'tempfile'
3
3
  require 'open3'
4
+ require 'coveralls'
5
+ Coveralls.wear!
4
6
 
5
7
  RdobaSimSimpleHead=<<HEAD
6
8
  #!/usr/bin/env ruby
data/lib/rdoba.rb CHANGED
@@ -1,20 +1,7 @@
1
1
  #encoding: utf-8
2
2
 
3
- #require 'rdoba/a'
4
- #require 'rdoba/dup'
5
- #require 'rdoba/require'
6
- #require 'rdoba/common'
7
- #require 'rdoba/debug'
8
- #require 'rdoba/yaml'
9
- #require 'rdoba/strings'
10
- #require 'rdoba/deploy'
11
- #require 'rdoba/roman'
12
- #require 'rdoba/combinations'
13
- #require 'rdoba/hashorder'
14
- #require 'rdoba/fenc'
15
-
16
3
  module Kernel
17
- Modules = [ :io, :seqnum, :version, :bcd ]
4
+ Modules = [ :bcd ]
18
5
 
19
6
  def rdoba *options
20
7
  options.each do |option|
@@ -22,12 +9,49 @@ module Kernel
22
9
  [ ( k = option.keys.shift ).to_s.to_sym, option[ k ] ] ||
23
10
  [ option.to_s.to_sym ] )
24
11
  case key
12
+ when :mixin
13
+ require "rdoba/mixin"
14
+ Rdoba.mixin value
25
15
  when :log, :debug
26
16
  require "rdoba/#{key}"
27
17
  Rdoba.log( { :in => self }.merge( value || {} ) ) # TODO move log method into module
28
- # and resolve some troubles with eval in main
29
- when :classmatch
30
- require 'rdoba/classmatch'
31
- self.extend Rdoba::ClassMatch
32
- else nil; end || if Modules.include? key
18
+ # TODO and resolve some troubles with eval in main
19
+ else
20
+ Kernel.puts STDERR, "Unknown rdoba module named as '#{key.to_s}'"
21
+ nil; end ||
22
+ if Modules.include? key
33
23
  require "rdoba/#{key}"; end; end; end; end
24
+
25
+ require 'rbconfig'
26
+
27
+ module Rdoba
28
+ def self.gemroot name = nil, path = ''
29
+ if !gem( name )
30
+ raise "Invalid gem named as #{name.inspect}" ; end
31
+ g = Gem::Specification.find_by_name( name )
32
+ File.join g.full_gem_path, path
33
+ end
34
+
35
+ def self.os
36
+ @@os ||= (
37
+ host_os = RbConfig::CONFIG['host_os']
38
+ case host_os
39
+ when /(mswin|msys|mingw|cygwin|bccwin|wince|emc)/
40
+ plat = $1 == 'mswin' && 'native' || $1
41
+ out = `ver`.encode( 'US-ASCII',
42
+ :invalid => :replace, :undef => :replace )
43
+ if out =~ /\[.* (\d+)\.([\d\.]+)\]/
44
+ "windows-#{plat}-#{$1 == '5' && 'xp' || 'vista'}-#{$1}.#{$2}"
45
+ else
46
+ "windows-#{plat}" ; end
47
+ when /darwin|mac os/
48
+ 'macosx'
49
+ when /linux/
50
+ 'linux'
51
+ when /(solaris|bsd)/
52
+ "unix-#{$1}"
53
+ else
54
+ raise "unknown os: #{host_os.inspect}"
55
+ end)
56
+ end ; end
57
+
@@ -1,3 +1,3 @@
1
1
  module Rdoba
2
- VERSION = "0.9"
2
+ VERSION = "0.9.1"
3
3
  end
data/lib/rdoba/a.rb CHANGED
@@ -1,56 +1,7 @@
1
1
  #!/usr/bin/ruby -KU
2
- #<Encoding:UTF-8>
2
+ #coding:utf-8
3
3
 
4
4
  require 'rdoba/debug'
5
- require 'rdoba/common'
6
-
7
- class Object
8
- def seta(index, value, options = {}) #TODO => [] + class Index
9
- raise "Invalid class #{self.class} to set a value" unless
10
- self.class == Hash or self.class == Array
11
- dbp11 "[seta] <<< index: #{index.inspect}, value: #{value.inspect}, options: #{options.inspect}"
12
- options[:сокр] ||= @сокр
13
-
14
- return self[index] = value if index.class != Array # TODO spec index
15
-
16
- back = 0
17
- index = index.reverse.map do |x|
18
- if x.empty?
19
- back += 1
20
- nil
21
- elsif back > 0
22
- back -= 1
23
- nil
24
- else
25
- x
26
- end
27
- end.compact.reverse
28
- dbp12 "[seta]> result index: #{index.inspect}"
29
-
30
- par = self
31
- par_idx = index.shift
32
- index.each do |idx|
33
- dbp14 "[seta]>> parent #{par.class} with idx: #{par_idx.inspect}"
34
- obj = par[par_idx]
35
- if not obj
36
- obj = idx.to_s =~ /^\d+$/ && [] || {}
37
- par[par_idx] = obj
38
- dbp14 "[seta]>> new object #{obj.class}"
39
- elsif obj.class != Hash and obj.class != Array
40
- raise "Invalid class #{obj.class} for indexing"
41
- end
42
-
43
- par = obj
44
- par_idx = idx
45
- end
46
-
47
- dbp14 "[seta]>> object #{par.class} with idx: #{par_idx.inspect}"
48
-
49
- par[par_idx] = value
50
- dbp11 "[seta] >>> #{self.inspect}"
51
- self
52
- end
53
- end
54
5
 
55
6
  class Array
56
7
  def geta(index, options = {}) #TODO => [] + class Index
@@ -60,12 +11,13 @@ class Array
60
11
  if index.class == Array
61
12
  return self if index == [] or index == ['']
62
13
  index = index.clone
63
- value = self[index.shift.to_i]
14
+ value = self[index.shift]
64
15
  (value.class == Hash or value.class == Array) ? value.geta(index, options) : value
65
16
  else
66
17
  geta_value(index, options)
67
18
  end
68
19
  end
20
+
69
21
  end
70
22
 
71
23
 
@@ -107,5 +59,56 @@ public
107
59
  geta_value(index, options)
108
60
  end
109
61
  end
62
+
63
+ def seta(index, value, options = {}) #TODO => [] + class Index
64
+ dbp11 "[seta] <<< index: #{index.inspect}, value: #{value.inspect}, options: #{options.inspect}"
65
+ options[:сокр] ||= @сокр
66
+
67
+ return self[index] = value if index.class != Array # TODO spec index
68
+
69
+ back = 0
70
+ index = index.reverse.map do |x|
71
+ if x.empty?
72
+ back += 1
73
+ nil
74
+ elsif back > 0
75
+ back -= 1
76
+ nil
77
+ else
78
+ x
79
+ end
80
+ end.compact.reverse
81
+ dbp12 "[seta]> result index: #{index.inspect}"
82
+
83
+ obj = nil
84
+ o = self
85
+ dbp14 "[seta]>> self: #{o.inspect}"
86
+ set_idx = index.pop
87
+ par_class = set_idx =~ /^\d+$/ ? Array : Hash
88
+ par_idx = nil
89
+ index.each do |idx|
90
+ unless o
91
+ dbp14 "[seta]>> parent idx: #{par_idx.inspect}, idx: #{idx.inspect}, parent obj: #{o.inspect}"
92
+ o = idx =~ /^\d+$/ && [] || {}
93
+ obj[par_idx] = o
94
+ end
95
+ obj = o
96
+ o = (obj.class == Hash) ? obj.geta_value(idx, options) : obj[idx]
97
+ dbp14 "[seta]>> cur idx: #{idx.inspect}, parent obj: #{obj.inspect}, obj: #{o.inspect}"
98
+ unless o
99
+ if idx == index.last
100
+ o = par_class.new
101
+ obj[idx] = o
102
+ else
103
+ par_idx = idx =~ /^\d+$/ && idx.to_i || idx
104
+ end
105
+ end
106
+ end
107
+
108
+ raise "Invalid path" unless o # TODO special exception
109
+
110
+ o[set_idx] = value
111
+ end
112
+
110
113
  end
111
114
 
data/lib/rdoba/common.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/ruby -KU
2
- #<Encoding:UTF-8>
2
+ #coding:utf-8
3
3
 
4
4
  class Object
5
5
  def xor(val1)
@@ -38,15 +38,17 @@ class Object
38
38
  end
39
39
 
40
40
  module Kernel
41
- require 'timeout'
41
+ def wait_if(timeout = 30)
42
+ require 'timeout'
42
43
 
43
- def if_wait(timeout = 30)
44
- Timeout::timeout(timeout) do
45
- while yield(); end
44
+ begin
45
+ Timeout::timeout(timeout) do
46
+ while yield(); end
47
+ end
48
+ true
49
+ rescue Timeout::Error
50
+ false
46
51
  end
47
- true
48
- rescue Timeout::Error
49
- false
50
52
  end
51
53
  end
52
54
 
@@ -102,17 +104,6 @@ class Array
102
104
  return __set__(index.to_i, value, *args) if index.class == String and index =~ /^\d+$/
103
105
  __set__(index, value, *args)
104
106
  end
105
-
106
- def glue!(inval)
107
- self.each_index do |i|
108
- begin
109
- self[i] |= inval[i]
110
- rescue
111
- self[i] = inval[i]
112
- end if inval[i]
113
- end
114
- self
115
- end
116
107
  end
117
108
 
118
109
  class String
@@ -157,36 +148,14 @@ class String
157
148
  end
158
149
 
159
150
  class Hash
160
- def glue!(inval)
161
- self.replace self.glue(inval)
162
- end
163
-
164
- def glue(inval)
165
- res = self.dup
166
- inval.each_pair do |key, val|
167
- if val.class == res[key].class
168
- if val.class == Hash
169
- res[key].glue! val
170
- elsif val.class == Array
171
- res[key].glue! val
172
- else
173
- res[key] = val
174
- end
175
- else
176
- res[key] = val
177
- end
178
- end
179
- res
180
- end
181
-
182
151
  def |(inval)
183
152
  res = self.dup
184
153
  inval.each_pair do |key, val|
185
154
  if val.class == res[key].class
186
155
  if val.class == Hash
187
- res[key] |= val
156
+ res[key] |= inval[key]
188
157
  elsif val.class == Array
189
- res[key] |= val
158
+ res[key].concat val
190
159
  else
191
160
  res[key] = val
192
161
  end
data/lib/rdoba/deploy.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/ruby -KU
2
- #<Encoding:UTF-8>
2
+ #coding:utf-8
3
3
 
4
4
  require 'rdoba/common'
5
5
 
data/lib/rdoba/dup.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/ruby -KU
2
- #<Encoding:UTF-8>
2
+ #coding:utf-8
3
3
 
4
4
  class Array
5
5
  alias :__dup__ :dup
data/lib/rdoba/gem.rb ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/ruby -KU
2
+ #encoding:utf-8
3
+
4
+ require 'rbconfig'
5
+
6
+ module Rdoba
7
+ def self.gemroot gemname = nil, path = ''
8
+ if !gem
9
+ raise "Undefined gem name" ; end
10
+ g = Gem::Specification.find_by_name( gemname )
11
+ File.join g.full_gem_path, 'share', 'settings.yaml'
12
+ end
13
+
14
+ def self.os
15
+ @@os ||= (
16
+ host_os = RbConfig::CONFIG['host_os']
17
+ case host_os
18
+ when /(mswin|msys|mingw|cygwin|bccwin|wince|emc)/
19
+ plat = $1 == 'mswin' && 'native' || $1
20
+ out = `ver`.encode( 'US-ASCII',
21
+ :invalid => :replace, :undef => :replace )
22
+ if out =~ /\[.* (\d+)\.([\d\.]+)\]/
23
+ "windows-#{plat}-#{$1 == '5' && 'xp' || 'vista'}-#{$1}.#{$2}"
24
+ else
25
+ "windows-#{plat}" ; end
26
+ when /darwin|mac os/
27
+ 'macosx'
28
+ when /linux/
29
+ 'linux'
30
+ when /(solaris|bsd)/
31
+ "unix-#{$1}"
32
+ else
33
+ raise "unknown os: #{host_os.inspect}"
34
+ end)
35
+ end ; end
36
+
data/lib/rdoba/io.rb CHANGED
@@ -1,5 +1,5 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
1
+ #!/usr/bin/ruby -KU
2
+ #coding:utf-8
3
3
 
4
4
  require 'strscan'
5
5
  require 'rdoba/re'
@@ -11,7 +11,6 @@ module Kernel
11
11
  def sprintf(format, *args)
12
12
  nargs = []
13
13
  nformat = ''
14
- oargs = args.dup
15
14
 
16
15
  fmt = format.split('%')
17
16
  nformat = fmt.shift
@@ -19,46 +18,23 @@ module Kernel
19
18
  while (not fmt.empty?)
20
19
  part = fmt.shift
21
20
  part = '%' + fmt.shift unless part
22
- if part =~ /([0-9 #+\-*.]*)([csXx])(.*)/ # other keys bdEefGgiopu
21
+ if part =~ /([0-9 #+\-*.]*)([bcdEefGgiopsuXxP])(.*)/ and $2 == 'P'
23
22
  keys = $1 || ''
24
- rest = $3 || ''
25
- char = $2
26
- if keys =~ /(?:([0-9*]*)\.([0-9*]+)([+-])?|(-)?)/
27
- indent = ( $1 == '*' && args.shift || $1 ).to_i
28
- padding_size = $2 == '*' && args.shift.to_i || $2
23
+ str = $3 || ''
24
+ if keys =~ /(-)?([0-9*]*)\.?([0-9\*]*)(\+?)/
29
25
  value = args.shift
30
- def convert( value, char, *args )
31
- case char
32
- when 'c'
33
- endian = args[ 1 ] == '+' && Fixnum::BigEndian ||
34
- args[ 1 ] == '-' && Fixnum::LittleEndian ||
35
- Fixnum::NativeEndian
36
- value.to_i.to_p( :padding => ( args[ 0 ] && args[ 0 ].to_i || 1 ),
37
- :endian => endian )
38
- when 's'
39
- rs = value.to_s
40
- pad = args[ 0 ] && args[ 0 ].to_i || 0
41
- padl = rs.size >= pad && '' || ( "\0" * ( pad - rs.size ) )
42
- args[ 1 ] && ( padl + rs ) || ( rs + padl )
43
- when /(x|X)/
44
- rs = value.ord.to_s( 16 )
45
- rs = rs.upcase if $1 == 'X'
46
- pad = args[ 0 ] && args[ 0 ].to_i || 0
47
- ( rs.size >= pad && '' || ( '0' * ( pad - rs.size ) ) ) + rs
48
- end.gsub( Regexp.new( '%', Regexp::EXTENDED | Regexp::MULTILINE ),
49
- '%%' )
50
- end
51
- plain = value && convert( value, char, padding_size, $3 ) || ''
52
- indent = indent > plain.size && ( indent - plain.size ) || 0
53
- nformat += ( $4 && ( plain + ' ' * indent ) ||
54
- ( ' ' * indent + plain ) ) + rest
26
+ indent = ' ' * ($2 == '*' ? args.shift : $2).to_i
27
+ plain = value && value.to_p(
28
+ :padding => ($3 == '*' ? args.shift : $3.empty? ? 1 : $3).to_i,
29
+ :be => $4.empty? ? nil : true) || ''
30
+ nformat += ($1 ? plain + indent : indent + plain) + str
55
31
  else
56
- nformat += '%' + keys + char + rest
32
+ nformat += '%' + keys + 'c' + str
57
33
  nargs.push args.shift
58
34
  end
59
35
  else
60
36
  nformat += '%' + part
61
- l = $1 =~ /\*/ && 2 || 1
37
+ l = $1 =~ /\*/ ? 2 : 1
62
38
  while l > 0
63
39
  nargs.push args.shift
64
40
  l -= 1
@@ -66,11 +42,8 @@ module Kernel
66
42
  end
67
43
  end
68
44
  __sprintf__(nformat, *nargs).to_p
69
- rescue ArgumentError
70
- Kernel.puts "[sprintf] #{$!.class}: #{$!}\n\t" + $@.join("\n\t") +
71
- "\n\tNew format string = #{nformat.inspect}, params = #{nargs.inspect}" +
72
- "\n\tOld format string = #{format.inspect}, params = #{oargs.inspect}"
73
45
  end
46
+
74
47
  end
75
48
 
76
49
  class String
@@ -80,7 +53,7 @@ class String
80
53
 
81
54
  pos = 0
82
55
  argfs = []
83
- while fss.scan_until(/%([0-9 #+\-*]*)(?:\.([0-9]+)([-+])?)?([bcdefgiosuxr])/)
56
+ while fss.scan_until(/%([0-9 #+\-*]*)(?:\.([0-9]+)(\+)?)?([bcdefgiosuxr])/)
84
57
  argfs << [ fss[1], fss[2], fss[3], fss[4] ]
85
58
  # TODO add performing the special case in fss[1]
86
59
  nformat += fss.pre_match[pos..-1].to_res + case fss[4]
@@ -97,7 +70,7 @@ class String
97
70
  when 'g'
98
71
  '([+\-]?[0-9]+(?:[eE][+\-]?[0-9]+|\.[0-9]*))'
99
72
  when 'c'
100
- fss[2] ? "(.{#{fss[2]},#{fss[2]}})" : "(.)"
73
+ fss[2] ? "(.{1,#{fss[2]}})" : "(.)"
101
74
  when 'b'
102
75
  '([01]+)b?'
103
76
  when 'o'
@@ -115,7 +88,7 @@ class String
115
88
 
116
89
  nformat += fss.rest
117
90
 
118
- [ r3 = Regexp.new(nformat, Regexp::EXTENDED | Regexp::MULTILINE), argfs ]
91
+ [ /#{nformat}/, argfs ]
119
92
  end
120
93
 
121
94
  (alias :__scanf__ :scanf) if self.instance_methods(false).include?(:scanf)
@@ -137,10 +110,7 @@ class String
137
110
  when /[efg]/
138
111
  value.to_f
139
112
  when 'c'
140
- endian = argf[2] == '+' && Fixnum::BigEndian ||
141
- argf[2] == '-' && Fixnum::LittleEndian ||
142
- Fixnum::NativeEndian
143
- value.to_i( endian )
113
+ argf[2] ? value.to_i(:be) : value.to_i
144
114
  when 'b'
145
115
  value.to_i(2)
146
116
  when 'o'
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/ruby -KU
2
+ #encoding:utf-8
3
+
4
+ module Rdoba
5
+ module Mixin
6
+ module To_hArray
7
+ def to_h options = {}
8
+ h = {}
9
+ self.each do |v|
10
+ if v.is_a? Array
11
+ if h.key? v[ 0 ]
12
+ if !h[ v[ 0 ] ].is_a? Array
13
+ h[ v[ 0 ] ] = [ h[ v[ 0 ] ] ] ; end
14
+
15
+ if v.size > 2
16
+ h[ v [ 0 ] ].concat v[ 1..-1 ]
17
+ else
18
+ h[ v [ 0 ] ] << v[ 1 ] ; end
19
+ else
20
+ h[ v[ 0 ] ] = v.size > 2 && v[ 1..-1] || v[ 1 ] ; end
21
+ else
22
+ if h.key? v
23
+ if !h[ v ].is_a? Array
24
+ h[ v ] = [ h[ v ] ] ; end
25
+
26
+ h[ v ] << v
27
+ else
28
+ h[ v ] = nil ; end ; end ; end
29
+
30
+ if options[ :save_unique ]
31
+ h.each_pair do |k,v|
32
+ if v.is_a? Array
33
+ v.uniq! ; end ; end ; end
34
+
35
+ h ; end ; end
36
+
37
+ module EmptyObject
38
+ def empty?
39
+ false ; end ; end
40
+
41
+ module EmptyNilClass
42
+ def empty?
43
+ true ; end ; end ; end
44
+
45
+ def self.mixin options
46
+ ( options || [] ).each do |value|
47
+ case value
48
+ when :to_h
49
+ Array.send :include, Rdoba::Mixin::To_hArray
50
+ when :empty
51
+ Object.send :include, Rdoba::Mixin::EmptyObject
52
+ NilClass.send :include, Rdoba::Mixin::EmptyNilClass
53
+ else
54
+ Kernel.puts STDERR, "Invalid rdoba-mixin options key: #{value.to_s}"
55
+ end ; end ; end ; end
56
+
57
+
data/lib/rdoba/numeric.rb CHANGED
@@ -1,51 +1,68 @@
1
1
  #!/usr/bin/ruby -KU
2
- #<Encoding:UTF-8>
2
+ #coding:utf-8
3
3
 
4
4
  require 'rdoba/common'
5
5
  require 'rdoba/strings'
6
6
 
7
- class Fixnum
8
- NativeEndian = 0
9
- LittleEndian = -1
10
- BigEndian = -2
7
+ class String
8
+ alias :_rdoba_to_i :to_i
9
+ def to_i(base = 10, *opts)
10
+ v = parse_opts(opts)
11
+ if v[:be]
12
+ (str, sign, num) = (self.match /\s*(-?)([0-9a-fx]+)/u).to_a
13
+ if str
14
+ n = num.reverse._rdoba_to_i(base)
15
+ sign.empty? && n || -n
16
+ else
17
+ 0
18
+ end
19
+ else
20
+ _rdoba_to_i(base)
21
+ end
22
+ end
23
+ end
11
24
 
25
+ class Fixnum
12
26
  alias :_rdoba_to_s :to_s
13
- def to_s( base = 10, opts = {} )
14
- if !opts[ :padding ] && !opts[ :style_formatting ]
15
- return _rdoba_to_s( base ); end
27
+ def to_s(base = 10, *opts)
28
+ v = parse_opts(opts)
16
29
 
17
- if base <= 0
18
- raise "Base of number can't be equal or less then zero"; end
19
- if opts[ :padding ] <= 0
20
- raise "Padding count numberr can't be equal or less then zero"; end
30
+ return _rdoba_to_s(base) unless v[:padding] or v[:style_formatting]
21
31
 
32
+ raise "Base of number can't be equal or less then zero" if base <= 0
33
+ raise "Padding count numberr can't be equal or less then zero" if v[:padding] <= 0
22
34
  value = self
23
- minus = value < 0 && ( value = -value; true )
35
+ minus = if value < 0
36
+ value = -value
37
+ true
38
+ end
24
39
  res = ''
25
40
  while value != 0
26
41
  value, rem = value.divmod(base)
27
42
  rem += 0x40 - 0x39 if rem >= 10
28
- res += (0x30 + rem).chr; end
29
-
30
- if res.size < ( padding = opts[ :padding ].to_i )
31
- res += "0" * ( padding - res.size ); end
32
- if opts[ :style_formatting ] and base == 16
33
- res += 'x0'; end
34
- if minus
35
- res += '-';end
36
-
43
+ res += (0x30 + rem).chr
44
+ end
45
+ res += "0" * (v[:padding].to_i - res.size) if res.size < v[:padding].to_i
46
+ res += 'x0' if v[:style_formatting] and base == 16
47
+ res += '-' if minus
37
48
  res.reverse
38
49
  end
39
50
  end
40
51
 
41
52
  class Numeric
42
- def to_p( opts = {} )
53
+ def to_p(*opts)
54
+ v = parse_opts(opts)
55
+
43
56
  value = self
44
- minus = value < 0 && ( value = -value; true )
57
+ minus = if value < 0
58
+ value = -value
59
+ true
60
+ end
45
61
  res = ''
46
62
  while value != 0
47
63
  value, rem = value.divmod(256)
48
- res += rem.chr; end
64
+ res += rem.chr
65
+ end
49
66
 
50
67
  pad_char = if minus
51
68
  negres += ''
@@ -57,46 +74,19 @@ class Numeric
57
74
  0
58
75
  else
59
76
  over = 0
60
- negbyte; end; end
77
+ negbyte
78
+ end
79
+ end
61
80
  res = negres
62
81
  "\xFF"
63
82
  else
64
- "\0"; end
65
-
66
- if res.size < ( padding = opts[ :padding ].to_i )
67
- res += pad_char * ( padding - res.size ); end
83
+ "\0"
84
+ end
68
85
 
69
- #TODO add detection of endianness of current system
70
- if ( endian = opts[ :endian ] || Fixnum::NativeEndian ) ==
71
- Fixnum::NativeEndian
72
- endian = Fixnum::LittleEndian; end
73
- ( ( endian == Fixnum::LittleEndian ) && res ||
74
- res.reverse( String::ByteByByte ) ).to_p; end; end
86
+ res += pad_char * (v[:padding].to_i - res.size) if res.size < v[:padding].to_i
75
87
 
76
- class String
77
- alias :_rdoba_to_i :to_i
78
- def to_i( base = 10 )
79
- return 0 if self.empty?
80
-
81
- #TODO add detection of endianness of current system
82
- if base == Fixnum::NativeEndian
83
- base = Fixnum::LittleEndian; end
84
- res = 0
85
- if base == Fixnum::BigEndian
86
- self.each_byte do |b|
87
- res = ( res << 8 ) | b
88
- end
89
- res
90
- elsif base == Fixnum::LittleEndian
91
- size = self.size
92
- (1..size).each do |i|
93
- b = self.getbyte( size - i )
94
- res = ( res << 8 ) | b
95
- end
96
- res
97
- else
98
- _rdoba_to_i base
99
- end
88
+ plain = (v[:be] ? res.reverse(String::ByteByByte) : res).to_p
89
+ plain
100
90
  end
101
91
  end
102
92
 
data/lib/rdoba/re.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/ruby -KU
2
- #<Encoding:UTF-8>
2
+ #coding:utf-8
3
3
 
4
4
  class String
5
5
  def to_res
data/lib/rdoba/require.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/ruby -KU
2
- #<Encoding:UTF-8>
2
+ #coding:utf-8
3
3
 
4
4
  require 'rdoba/common'
5
5
  require 'rdoba/debug'
data/lib/rdoba/strings.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/ruby -KU
2
- #<Encoding:UTF-8>
2
+ #coding:utf-8
3
3
 
4
4
  class String
5
5
 
@@ -92,16 +92,15 @@ class String
92
92
  alias :to_p :to_s
93
93
 
94
94
  ByteByByte = 0
95
- alias :of_rdoba_reverse :reverse
96
- def reverse( step = 1 )
97
- # of Plain
95
+ alias :__reverse__ :reverse
96
+ def reverse(step = 1)
98
97
  case step
99
98
  when ByteByByte
100
99
  arr = []
101
100
  self.each_byte do |byte| arr << byte.chr end
102
101
  arr.reverse.join
103
102
  when 1
104
- of_rdoba_reverse
103
+ __reverse__
105
104
  else
106
105
  res = ''
107
106
  offset = (self.size + 1) / step * step - step
data/rdoba.gemspec CHANGED
@@ -23,7 +23,10 @@ Gem::Specification.new do |s|
23
23
  s.extra_rdoc_files = [ 'README.md', 'LICENSE' ]
24
24
 
25
25
  s.required_rubygems_version = '>= 1.6.0'
26
+ s.required_ruby_version = '>= 1.9.0'
26
27
 
27
- s.add_development_dependency 'bundler', '~> 1.3.1'
28
- s.add_development_dependency 'cucumber'
28
+ s.add_development_dependency 'rake'
29
+ s.add_development_dependency 'bundler', '~> 1.3'
30
+ s.add_development_dependency 'cucumber', '~> 1.3'
31
+ s.add_development_dependency 'coveralls'
29
32
  end
metadata CHANGED
@@ -1,54 +1,65 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rdoba
3
- version: !ruby/object:Gem::Version
4
- version: '0.9'
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.1
5
5
  platform: ruby
6
- authors:
7
- - Малъ Скрылёвъ (Malo Skrylevo)
6
+ authors:
7
+ - "\xD0\x9C\xD0\xB0\xD0\xBB\xD1\x8A \xD0\xA1\xD0\xBA\xD1\x80\xD1\x8B\xD0\xBB\xD1\x91\xD0\xB2\xD1\x8A (Malo Skrylevo)"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-15 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
11
+
12
+ date: 2013-10-01 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - &id005
19
+ - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: "0"
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *id001
25
+ - !ruby/object:Gem::Dependency
14
26
  name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
27
+ requirement: &id002 !ruby/object:Gem::Requirement
28
+ requirements:
17
29
  - - ~>
18
- - !ruby/object:Gem::Version
19
- version: 1.3.1
30
+ - &id003 !ruby/object:Gem::Version
31
+ version: "1.3"
20
32
  type: :development
21
33
  prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ~>
25
- - !ruby/object:Gem::Version
26
- version: 1.3.1
27
- - !ruby/object:Gem::Dependency
34
+ version_requirements: *id002
35
+ - !ruby/object:Gem::Dependency
28
36
  name: cucumber
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
37
+ requirement: &id004 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - *id003
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: *id004
44
+ - !ruby/object:Gem::Dependency
45
+ name: coveralls
46
+ requirement: &id006 !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - *id005
34
49
  type: :development
35
50
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- description: Ruby extension library. It extends Kernel, Object, String, Hash, Array,
42
- and some other classes. Also allows to log application state with debug lines to
43
- an io
44
- email:
51
+ version_requirements: *id006
52
+ description: Ruby extension library. It extends Kernel, Object, String, Hash, Array, and some other classes. Also allows to log application state with debug lines to an io
53
+ email:
45
54
  - 3aHyga@gmail.com
46
55
  executables: []
56
+
47
57
  extensions: []
48
- extra_rdoc_files:
58
+
59
+ extra_rdoc_files:
49
60
  - README.md
50
61
  - LICENSE
51
- files:
62
+ files:
52
63
  - .document
53
64
  - .gitignore
54
65
  - CHANGES.md
@@ -71,45 +82,49 @@ files:
71
82
  - lib/rdoba/deploy.rb
72
83
  - lib/rdoba/dup.rb
73
84
  - lib/rdoba/fe.rb
85
+ - lib/rdoba/gem.rb
74
86
  - lib/rdoba/hashorder.rb
75
87
  - lib/rdoba/io.rb
76
88
  - lib/rdoba/log.rb
89
+ - lib/rdoba/mixin.rb
77
90
  - lib/rdoba/numeric.rb
78
91
  - lib/rdoba/re.rb
79
92
  - lib/rdoba/require.rb
80
93
  - lib/rdoba/roman.rb
81
94
  - lib/rdoba/strings.rb
82
- - lib/rdoba/version.rb
83
95
  - lib/rdoba/yaml.rb
84
96
  - rdoba.gemspec
85
97
  - test/helper.rb
86
98
  - test/rdoba_test.rb.stub
87
99
  - test/test_rdoba.rb
88
100
  homepage: https://github.com/3aHyga/rdoba
89
- licenses:
101
+ licenses:
90
102
  - MIT
91
103
  metadata: {}
104
+
92
105
  post_install_message:
93
106
  rdoc_options: []
94
- require_paths:
107
+
108
+ require_paths:
95
109
  - lib
96
- required_ruby_version: !ruby/object:Gem::Requirement
97
- requirements:
98
- - - '>='
99
- - !ruby/object:Gem::Version
100
- version: '0'
101
- required_rubygems_version: !ruby/object:Gem::Requirement
102
- requirements:
103
- - - '>='
104
- - !ruby/object:Gem::Version
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 1.9.0
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
105
119
  version: 1.6.0
106
120
  requirements: []
121
+
107
122
  rubyforge_project: rdoba
108
- rubygems_version: 2.0.0
123
+ rubygems_version: 2.1.4
109
124
  signing_key:
110
125
  specification_version: 4
111
126
  summary: Ruby extension library (Ruby DOBAvka)
112
- test_files:
127
+ test_files:
113
128
  - features/bcd.feature
114
129
  - features/log.feature
115
130
  - features/step_definitions/bcd_steps.rb
data/lib/rdoba/version.rb DELETED
@@ -1,51 +0,0 @@
1
- #encoding: utf-8
2
-
3
- class Version
4
- attr_reader :subminor, :minor, :major
5
-
6
- def self.parse value
7
- case version.is_a?
8
- when self
9
- value
10
- when Array
11
- Version.new version[ 0 ].to_i, version[ 1 ].to_i, version[ 2 ].to_i
12
- when Numeric
13
- Version.new version >> 8, ( version >> 4 ) & 0xF, version & 0xF
14
- else
15
- if version.to_s =~ /(\d+)\.(\d+)(?:\.(\d+))?/
16
- Version.new $1.to_i, $2.to_i, $3.to_i
17
- elsif version.to_s =~ /([\da-z][\da-z])([\da-z])([\da-z])/i
18
- Version.new $1.to_i( 16 ), $2.to_i( 16 ), $3.to_i( 16 )
19
- else
20
- Version.new 0, 0, 0; end; end; end
21
-
22
- def == value
23
- v = self.parse value
24
- @major == v.major && @minor == v.minor && @subminor == v.subminor
25
- end
26
-
27
- def < value
28
- v = self.parse value
29
- @major < v.major || @major == v.major &&
30
- ( @minor < v.minor || @minor == v.minor &&
31
- @subminor < v.subminor ); end
32
-
33
- def > value
34
- v = self.parse value
35
- @major > v.major || @major == v.major &&
36
- ( @minor > v.minor || @minor == v.minor &&
37
- @subminor > v.subminor ); end
38
-
39
- def to_a
40
- [ @major, @minor, @subminor ]; end
41
-
42
- def to_s
43
- "#{@major}.#{@minor}.#{@subminor}"; end
44
-
45
- private
46
-
47
- def initialize major, minor = 0, subminor = 0
48
- @subminor = subminor
49
- @minor = minor
50
- @major = major; end; end
51
-