kyanite 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/0 start all Tests.bat +23 -0
- data/History.txt +4 -0
- data/License.txt +21 -0
- data/Manifest.txt +88 -0
- data/PostInstall.txt +4 -0
- data/README.txt +48 -0
- data/Rakefile.rb +79 -0
- data/init.rb +2 -0
- data/lib/kyanite.rb +39 -0
- data/lib/kyanite/array.rb +5 -0
- data/lib/kyanite/array/array.rb +172 -0
- data/lib/kyanite/array/array2.rb +140 -0
- data/lib/kyanite/array/matrix2.rb +120 -0
- data/lib/kyanite/array_of_enumerables.rb +2 -0
- data/lib/kyanite/array_of_numerics.rb +2 -0
- data/lib/kyanite/array_of_strings.rb +2 -0
- data/lib/kyanite/basics.rb +60 -0
- data/lib/kyanite/dictionary.rb +116 -0
- data/lib/kyanite/enumerable.rb +7 -0
- data/lib/kyanite/enumerable/enumerable_enumerables.rb +70 -0
- data/lib/kyanite/enumerable/enumerable_numerics.rb +171 -0
- data/lib/kyanite/enumerable/enumerable_strings.rb +58 -0
- data/lib/kyanite/enumerable/structure.rb +170 -0
- data/lib/kyanite/general.rb +8 -0
- data/lib/kyanite/general/callerutils.rb +128 -0
- data/lib/kyanite/general/classutils.rb +246 -0
- data/lib/kyanite/general/kernel.rb +105 -0
- data/lib/kyanite/general/nil.rb +64 -0
- data/lib/kyanite/general/object.rb +86 -0
- data/lib/kyanite/general/true_false.rb +65 -0
- data/lib/kyanite/general/undoable.rb +24 -0
- data/lib/kyanite/hash.rb +170 -0
- data/lib/kyanite/matrix2.rb +2 -0
- data/lib/kyanite/nil.rb +3 -0
- data/lib/kyanite/numeric.rb +4 -0
- data/lib/kyanite/numeric/float.rb +26 -0
- data/lib/kyanite/numeric/integer.rb +34 -0
- data/lib/kyanite/numeric/numeric.rb +45 -0
- data/lib/kyanite/operation.rb +5 -0
- data/lib/kyanite/operation/call_tracker.rb +69 -0
- data/lib/kyanite/operation/rake.rb +101 -0
- data/lib/kyanite/operation/regexp.rb +23 -0
- data/lib/kyanite/operation/unit_test.rb +53 -0
- data/lib/kyanite/optimizer.rb +119 -0
- data/lib/kyanite/rake.rb +2 -0
- data/lib/kyanite/range.rb +54 -0
- data/lib/kyanite/set.rb +219 -0
- data/lib/kyanite/smart_load_path.rb +2 -0
- data/lib/kyanite/string.rb +13 -0
- data/lib/kyanite/string/cast.rb +104 -0
- data/lib/kyanite/string/chars.rb +184 -0
- data/lib/kyanite/string/chars_const.rb +190 -0
- data/lib/kyanite/string/diff.rb +78 -0
- data/lib/kyanite/string/div.rb +19 -0
- data/lib/kyanite/string/include.rb +43 -0
- data/lib/kyanite/string/list.rb +84 -0
- data/lib/kyanite/string/mgsub.rb +35 -0
- data/lib/kyanite/string/nested.rb +253 -0
- data/lib/kyanite/string/random.rb +69 -0
- data/lib/kyanite/string/split.rb +136 -0
- data/lib/kyanite/symbol.rb +19 -0
- data/lib/kyanite/tree.rb +99 -0
- data/lib/kyanite/undoable.rb +2 -0
- data/lib/kyanite/unit_test.rb +2 -0
- data/test/_start_all.rb +17 -0
- data/test/array/test_array.rb +106 -0
- data/test/array/test_matrix2.rb +162 -0
- data/test/enumerable/test_enumerable_enumerables.rb +46 -0
- data/test/enumerable/test_enumerable_numerics.rb +93 -0
- data/test/enumerable/test_enumerable_strings.rb +22 -0
- data/test/enumerable/test_structure.rb +220 -0
- data/test/general/test_classutils.rb +45 -0
- data/test/general/test_nil.rb +44 -0
- data/test/general/test_object.rb +49 -0
- data/test/general/test_true_false.rb +28 -0
- data/test/numeric/test_numeric_integer.rb +28 -0
- data/test/string/test_cast.rb +108 -0
- data/test/string/test_chars.rb +255 -0
- data/test/string/test_diff.rb +95 -0
- data/test/string/test_list.rb +141 -0
- data/test/string/test_nested.rb +361 -0
- data/test/string/test_split.rb +187 -0
- data/test/test_dictionary.rb +128 -0
- data/test/test_hash.rb +59 -0
- data/test/test_optimizer.rb +150 -0
- data/test/test_range.rb +41 -0
- data/test/test_set.rb +210 -0
- data/test/test_tree.rb +94 -0
- metadata +217 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
class Integer
|
3
|
+
|
4
|
+
# Wandelt eine Sekundenzahl-seit-1970 in ein Time-Objekt
|
5
|
+
def to_time
|
6
|
+
return nil if self > 2099999999 # geht leider nur bis ins Jahr 2036
|
7
|
+
::Time.at(self) # ohne die Doppelpunkte sucht Ruby die Methode at in ::Time und wirft einen Error
|
8
|
+
end
|
9
|
+
|
10
|
+
# <tt> self </tt>
|
11
|
+
#
|
12
|
+
# Test: TestInteger#test_triviales
|
13
|
+
def to_integer; self; end
|
14
|
+
|
15
|
+
# <tt> self </tt>
|
16
|
+
#
|
17
|
+
# Test: TestInteger#test_triviales
|
18
|
+
def to_integer_optional; self; end
|
19
|
+
|
20
|
+
# <tt> self </tt>
|
21
|
+
#
|
22
|
+
# Test: TestInteger#test_triviales
|
23
|
+
def dup; self; end
|
24
|
+
|
25
|
+
end # class
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
class NilClass
|
30
|
+
def to_time; nil; end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
class Numeric
|
3
|
+
|
4
|
+
# Zahlen sind schon numerisch:
|
5
|
+
# <tt> self </tt>
|
6
|
+
def split_numeric #:nodoc:
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
# Zahlen sind nicht empty:
|
12
|
+
# <tt> false </tt>
|
13
|
+
def empty? #:nodoc:
|
14
|
+
false
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
# siehe ::Array#shift_complement:
|
19
|
+
# <tt> nil </tt>
|
20
|
+
def shift_complement #:nodoc:
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
# Wandelt 0 in nil um
|
26
|
+
def to_nil(*args)
|
27
|
+
return nil if self == 0
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# nil-sicheres subtrahieren
|
33
|
+
def substract(other)
|
34
|
+
return nil if other.nil?
|
35
|
+
self - other
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
end # class
|
41
|
+
|
42
|
+
|
43
|
+
class NilClass
|
44
|
+
def substract(other); nil; end
|
45
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
# http://oreilly.com/catalog/9780596523695/
|
5
|
+
# Ruby Cookbook, by Lucas Carlson and Leonard Richardson
|
6
|
+
# Copyright 2006 O'Reilly Media
|
7
|
+
#
|
8
|
+
class CallTracker
|
9
|
+
|
10
|
+
# Initialize and start the trace.
|
11
|
+
def initialize(show_stack_depth=1)
|
12
|
+
@show_stack_depth = show_stack_depth
|
13
|
+
@to_trace = Hash.new { |h,k| h[k] = {} }
|
14
|
+
start
|
15
|
+
at_exit { stop }
|
16
|
+
end
|
17
|
+
|
18
|
+
# Register a class/method combination as being interesting. Subsequent calls
|
19
|
+
# to the method will be tallied by tally_calls.
|
20
|
+
def register(klass, method_symbol)
|
21
|
+
@to_trace[klass][method_symbol] = {}
|
22
|
+
end
|
23
|
+
|
24
|
+
# Tells the Ruby interpreter to call tally_calls whenever it's about to
|
25
|
+
# do anything interesting.
|
26
|
+
def start
|
27
|
+
set_trace_func method(:tally_calls).to_proc
|
28
|
+
end
|
29
|
+
|
30
|
+
# Stops the profiler, and prints a report of the interesting calls made
|
31
|
+
# while it was running.
|
32
|
+
def stop(out=$stderr)
|
33
|
+
set_trace_func nil
|
34
|
+
report(out)
|
35
|
+
end
|
36
|
+
|
37
|
+
# If the interpreter is about to call a method we find interesting,
|
38
|
+
# increment the count for that method.
|
39
|
+
def tally_calls(event, file, line, symbol, binding, klass)
|
40
|
+
if @to_trace[klass] and @to_trace[klass][symbol] and
|
41
|
+
(event == 'call' or event =='c-call')
|
42
|
+
stack = caller
|
43
|
+
stack = stack[1..(@show_stack_depth ? @show_stack_depth : stack.size)]
|
44
|
+
@to_trace[klass][symbol][stack] ||= 0
|
45
|
+
@to_trace[klass][symbol][stack] += 1
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Prints a report of the lines of code that called interesting
|
50
|
+
# methods, sorted so that the the most active lines of code show up
|
51
|
+
# first.
|
52
|
+
def report(out=$stderr)
|
53
|
+
first = true
|
54
|
+
@to_trace.each do |klass, symbols|
|
55
|
+
symbols.each do |symbol, calls|
|
56
|
+
total = calls.inject(0) { |sum, ct| sum + ct[1] }
|
57
|
+
padding = total.to_s.size
|
58
|
+
separator = (klass.is_a? Class) ? '#' : '.'
|
59
|
+
plural = (total == 1) ? '' : 's'
|
60
|
+
stack_join = "\n" + (' ' * (padding+2))
|
61
|
+
first ? first = false : out.puts
|
62
|
+
out.puts "#{total} call#{plural} to #{klass}#{separator}#{symbol}"
|
63
|
+
(calls.sort_by { |caller, times| -times }).each do |caller, times|
|
64
|
+
out.puts " %#{padding}.d #{caller.join(stack_join)}" % times
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
|
2
|
+
# Dirty patch unter Windows um rake doc:plugins zum Laufen zu bringen: http://dev.rubyonrails.org/ticket/6608
|
3
|
+
|
4
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
5
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
6
|
+
# Doku der M�glichkeiten in einem RakeTask siehe http://rake.rubyforge.org/files/doc/rakefile_rdoc.html
|
7
|
+
|
8
|
+
|
9
|
+
# ----------------------------------------------------------------------------------------------
|
10
|
+
# Rake initialisieren
|
11
|
+
#
|
12
|
+
|
13
|
+
require 'rake'
|
14
|
+
require 'rake/testtask'
|
15
|
+
require 'rake/rdoctask'
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
# ----------------------------------------------------------------------------------------------
|
20
|
+
# Erg�nzung: Alte Tasks entfernen
|
21
|
+
# sonst kann man sie n�mlich nicht �berschreiben!
|
22
|
+
# Beispiel: remove_task 'test:plugins'
|
23
|
+
# Quelle: http://matthewbass.com/2007/03/07/overriding-existing-rake-tasks/
|
24
|
+
# dies hier stimmt nicht: http://www.dcmanges.com/blog/modifying-rake-tasks
|
25
|
+
|
26
|
+
Rake::TaskManager.class_eval do
|
27
|
+
def remove_task(task_name)
|
28
|
+
@tasks.delete(task_name.to_s)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def remove_task(task_name)
|
33
|
+
Rake.application.remove_task(task_name)
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
# ----------------------------------------------------------------------------------------------
|
38
|
+
# Taskliste versch�nern und als Default Task
|
39
|
+
#
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
remove_task 'default' # wichtig!
|
44
|
+
# desc 'Zeige eine Liste aller verfuegbaren Rake-Tasks'
|
45
|
+
task :default do
|
46
|
+
Rake.application.options.show_task_pattern = //
|
47
|
+
Rake.application.display_tasks_and_comments(:kurz)
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
module Rake # :nodoc:
|
52
|
+
class Application # :nodoc:
|
53
|
+
# Display the tasks and dependencies.
|
54
|
+
def display_tasks_and_comments( myoptions = nil )
|
55
|
+
$rake_tasks_ausblenden = [] unless defined? $rake_tasks_ausblenden
|
56
|
+
namespace_akt = ''
|
57
|
+
namespace_prev = ''
|
58
|
+
newline_allowed = true
|
59
|
+
displayable_tasks = tasks.select { |t| t.comment && t.name =~ options.show_task_pattern }
|
60
|
+
width = displayable_tasks.collect { |t| t.name.length }.max
|
61
|
+
all_namespaces = []
|
62
|
+
skipped_tasks = []
|
63
|
+
displayable_tasks.each do |t|
|
64
|
+
foo = t.name.split(':')
|
65
|
+
next if foo.size < 2
|
66
|
+
all_namespaces << foo[0]
|
67
|
+
end
|
68
|
+
all_namespaces.uniq!
|
69
|
+
#puts all_namespaces.join(',')
|
70
|
+
|
71
|
+
|
72
|
+
# Mit Namespace oder Taskname == Namespace
|
73
|
+
displayable_tasks.each do |t|
|
74
|
+
next if ( myoptions == :kurz && $rake_tasks_ausblenden.include?(t.name) )
|
75
|
+
foo = t.name.split(':')
|
76
|
+
if foo.size < 2
|
77
|
+
unless all_namespaces.include?(foo[0]) # Taskname == Namespace
|
78
|
+
skipped_tasks << t
|
79
|
+
next
|
80
|
+
end
|
81
|
+
end
|
82
|
+
namespace_akt = foo[0]
|
83
|
+
puts "\n" if namespace_akt != namespace_prev
|
84
|
+
printf "#{name} %-#{width}s # %s\n", t.name, t.comment
|
85
|
+
namespace_prev = namespace_akt.dup
|
86
|
+
end # do
|
87
|
+
|
88
|
+
puts "\n"
|
89
|
+
skipped_tasks.each do |t|
|
90
|
+
next if ( myoptions == :kurz && $rake_tasks_ausblenden.include?(t.name) )
|
91
|
+
printf "#{name} %-#{width}s # %s\n", t.name, t.comment
|
92
|
+
end # do
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
puts "\nsee full task list with rake -T" #unless ($rake_tasks_ausblenden.empty? || myoptions == :kurz )
|
97
|
+
puts "\nsee full task list with rake -T" unless ($rake_tasks_ausblenden.empty? || myoptions == :kurz )
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
class String
|
5
|
+
|
6
|
+
# Zeigt das Ergebnis eines Matches mit einer Regular Expression. Erleichtert das Entwickeln regul�rer Ausdr�cke.
|
7
|
+
#
|
8
|
+
def show_regexp(re)
|
9
|
+
if self =~ re
|
10
|
+
"#{$`}<<#{$&}>>#{$'}"
|
11
|
+
else
|
12
|
+
"no match"
|
13
|
+
end # if
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
class NilClass
|
20
|
+
def show_regexp(*a); nil; end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
require 'test/unit'
|
3
|
+
require 'kyanite/general/kernel' # smart_load_path
|
4
|
+
begin
|
5
|
+
require 'perception'
|
6
|
+
rescue
|
7
|
+
end
|
8
|
+
|
9
|
+
class UnitTest < Test::Unit::TestCase # :nodoc:
|
10
|
+
|
11
|
+
# Meldet den aktuell durchlaufenden Test
|
12
|
+
def test0 #:nodoc:
|
13
|
+
name = self.class.to_s.gsub(/^.*::/, '')
|
14
|
+
name.gsub!(/^Test/, '')
|
15
|
+
name.gsub!(/^[0-9]+/, '')
|
16
|
+
if name != 'UnitTest'
|
17
|
+
print "\n #{name} "
|
18
|
+
else
|
19
|
+
puts
|
20
|
+
puts
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
# ---------------------------------------------------------
|
35
|
+
# Ausprobieren
|
36
|
+
#
|
37
|
+
if $0 == __FILE__
|
38
|
+
|
39
|
+
class Test030Blatest < UnitTest # :nodoc:
|
40
|
+
|
41
|
+
def test_bla
|
42
|
+
# 1 / 0
|
43
|
+
assert false
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,119 @@
|
|
1
|
+
|
2
|
+
require 'perception' if $0 == __FILE__
|
3
|
+
|
4
|
+
# Drei Stufen für Marshall sind denkbar:
|
5
|
+
# * kein Marshal
|
6
|
+
# * Marshal.load(Marshal.dump) beim Schreiben. Dadurch sind Schreibzugriffe teuer, Lesezugriffe aber billig
|
7
|
+
# * Marshal.dump beim Schreiben, Marshal.load beim Lesen. Dadurch sind Lese- und Schreibzugriffe teuer,
|
8
|
+
# die im Optimizer gespeicherten Objekte sind aber abgeschottet und geschützt.
|
9
|
+
#
|
10
|
+
class Optimizer < Hash
|
11
|
+
|
12
|
+
#@@marshal = true
|
13
|
+
|
14
|
+
# def initialize( options={} )
|
15
|
+
# @@marshal = options[:marshal] || true
|
16
|
+
# end
|
17
|
+
|
18
|
+
|
19
|
+
def matchpoints_max
|
20
|
+
return nil if size == 0
|
21
|
+
keys.max
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
def matchpoints_min
|
27
|
+
return nil if size == 0
|
28
|
+
keys.min
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# Liefert den Content mit den meisten Matchpoints. Mit
|
33
|
+
# content_max(0) erhält man den ersten Content mit maximalen Matchpoints, mit
|
34
|
+
# content_max(-1) den letzten Content mit maximalen Matchpoints und mit
|
35
|
+
# content_max(0..-1) alle Contents mit maximalen Matchpoints (dann als Array).
|
36
|
+
#
|
37
|
+
def content_max(range=0..0)
|
38
|
+
return nil if size == 0
|
39
|
+
range = (range..range) if range.kind_of?(Fixnum)
|
40
|
+
if (range.end - range.begin) == 0
|
41
|
+
return Marshal.load(self[keys.max][range.begin])
|
42
|
+
else
|
43
|
+
result = []
|
44
|
+
self[keys.max][range].each do | m |
|
45
|
+
result << Marshal.load(m)
|
46
|
+
end
|
47
|
+
return result
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
# siehe content_max
|
53
|
+
def content_min(range=0..0)
|
54
|
+
return nil if size == 0
|
55
|
+
range = (range..range) if range.kind_of?(Fixnum)
|
56
|
+
if (range.end - range.begin) == 0
|
57
|
+
return Marshal.load(self[keys.min][range.begin])
|
58
|
+
else
|
59
|
+
result = []
|
60
|
+
self[keys.min][range].each do | m |
|
61
|
+
result << Marshal.load(m)
|
62
|
+
end
|
63
|
+
return result
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
def push( matchpoints, content, options={} )
|
70
|
+
if self.has_key?(matchpoints)
|
71
|
+
self[matchpoints] << Marshal.dump(content)
|
72
|
+
else
|
73
|
+
self[matchpoints] = [ Marshal.dump(content) ]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
def cleanup
|
80
|
+
return false if size <= 2
|
81
|
+
keys.sort[1..-2].each do | key |
|
82
|
+
self.delete(key)
|
83
|
+
end
|
84
|
+
true
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
def delete_min
|
89
|
+
return false if size <= 1
|
90
|
+
self.delete(keys.min)
|
91
|
+
true
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
def delete_max
|
96
|
+
return false if size <= 1
|
97
|
+
self.delete(keys.max)
|
98
|
+
true
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
end #class
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|