kyanite 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc CHANGED
@@ -1,3 +1,6 @@
1
+ == 0.7.5 2012-11-14
2
+ * added FSymbol class
3
+
1
4
  == 0.7.0 2012-10-31
2
5
  * some structure changes
3
6
  * englisch YARD documentation
data/Manifest.txt CHANGED
@@ -18,6 +18,7 @@ lib/kyanite/enumerable/enumerable_enumerables.rb
18
18
  lib/kyanite/enumerable/enumerable_numerics.rb
19
19
  lib/kyanite/enumerable/enumerable_strings.rb
20
20
  lib/kyanite/enumerable/structure.rb
21
+ lib/kyanite/fsymbol.rb
21
22
  lib/kyanite/general.rb
22
23
  lib/kyanite/general/callerutils.rb
23
24
  lib/kyanite/general/classutils.rb
@@ -64,6 +65,7 @@ test/string/test_misc.rb
64
65
  test/string/test_nested.rb
65
66
  test/string/test_split.rb
66
67
  test/test_dictionary.rb
68
+ test/test_fsymbol.rb
67
69
  test/test_hash.rb
68
70
  test/test_optimizer.rb
69
71
  test/test_range.rb
data/README.rdoc CHANGED
@@ -13,6 +13,7 @@ Welcome to Kyanite. It's a general toolbox like Facets or ActiveSupport.
13
13
  [{Hash} {Dictionary} {Tree::TreeNode Tree}] General tools.
14
14
  [{Optimizer}] Find objects with min or max score.
15
15
  [{Undoable}] Save and restore objects. Great for try-and-error-algorithms.
16
+ [{FSymbol}] A comparable {Symbol} within a hierarchy: A more specific {FSymbol} is larger than a more general {FSymbol}.
16
17
  [{Object} {CallerUtils}] Repeats a block until the time is up. Silence Ruby warnings. Deep copy. Examine the call stack.
17
18
 
18
19
 
data/Rakefile.rb CHANGED
@@ -22,8 +22,8 @@ $hoe = Hoe.spec Drumherum.project_name do
22
22
 
23
23
  developer('Bjoern Klippstein', 'klippstein@klippstein.com')
24
24
  summary = 'General toolbox like Facets or ActiveSupport.'
25
- extra_deps << ['drumherum', '>= 0.1.19']
26
- extra_deps << ['transparent_nil', '>= 0.1.7']
25
+ extra_deps << ['drumherum', '>= 0.1.34']
26
+ extra_deps << ['transparent_nil', '>= 0.1.20']
27
27
  extra_deps << ['activesupport', '>= 3.2.8']
28
28
  extra_deps << ['facets', '>= 2.9.3']
29
29
  extra_deps << ['rubytree', '>= 0.8.3']
@@ -0,0 +1,177 @@
1
+ # ruby encoding: utf-8
2
+ # ü
3
+ if $0 == __FILE__
4
+ require 'drumherum'
5
+ smart_init
6
+ end
7
+ require 'kyanite/tree'
8
+
9
+
10
+
11
+
12
+ # @!macro fsymbol
13
+ class FSymbol
14
+
15
+ attr_accessor :value
16
+ attr_accessor :childs
17
+ @@instance_cache = {}
18
+ @@def_tree_cache = nil
19
+
20
+ # @private
21
+ def self.instance_cache
22
+ @@instance_cache
23
+ end
24
+
25
+
26
+
27
+
28
+
29
+ def initialize( value, def_tree=nil)
30
+ raise ArgumentError, 'Value darf nicht nil sein!' if value.nil?
31
+ @value = value
32
+
33
+ if @@instance_cache[value]
34
+ @childs = @@instance_cache[value].childs
35
+ return @@instance_cache[value]
36
+ end
37
+
38
+ if def_tree.nil?
39
+ def_tree = @@def_tree_cache
40
+ else
41
+ @@def_tree_cache = def_tree
42
+ end
43
+ tree = def_tree.find(value) || nil
44
+ raise ArgumentError, "FSymbol konnte nicht erzeugt werden. Value :#{value} nicht im Definitionstree gefunden." if tree.nil?
45
+
46
+ @childs = tree.all_child_keys
47
+ @@instance_cache[value] = self
48
+ self
49
+ end
50
+
51
+
52
+ def to_s
53
+ @value.to_s
54
+ end
55
+
56
+
57
+ def inspect
58
+ @value.inspect
59
+ end
60
+
61
+
62
+ def <=>(other)
63
+ return nil if other.nil?
64
+ other = other.to_fsymbol unless other.class == FSymbol
65
+ return 0 if @value == other.value
66
+ return -1 if @childs.include?(other.value)
67
+ return 1 if other.childs.include?(@value)
68
+ return nil
69
+ end
70
+
71
+
72
+ def ==(other)
73
+ return nil if other.nil?
74
+ begin
75
+ (self <=> other) == 0
76
+ rescue
77
+ nil
78
+ end
79
+ end
80
+
81
+
82
+ def <=(other)
83
+ return nil if other.nil?
84
+ begin
85
+ c = (self <=> other)
86
+ (c == -1 || c == 0)
87
+ rescue
88
+ nil
89
+ end
90
+ end
91
+
92
+
93
+ def >=(other)
94
+ return nil if other.nil?
95
+ begin
96
+ c = (self <=> other)
97
+ (c == 1 || c == 0)
98
+ rescue
99
+ nil
100
+ end
101
+ end
102
+
103
+
104
+ def nil?
105
+ return true if @value.nil?
106
+ false
107
+ end
108
+
109
+
110
+ end
111
+
112
+
113
+
114
+ # -----------------------------------------------------------------------------------------
115
+ # Interface für Symbol
116
+ #
117
+ class Symbol
118
+
119
+ def to_fsymbol(def_tree=nil)
120
+ FSymbol.new(self, def_tree)
121
+ end
122
+
123
+ end
124
+
125
+
126
+
127
+
128
+
129
+
130
+ # -----------------------------------------------------------------------------------------
131
+ # Ausprobieren
132
+ #
133
+ if $0 == __FILE__ then
134
+
135
+ require 'perception'
136
+
137
+ unless defined? DEF_TREE
138
+ # Oberste Ebene
139
+ ttroot = Tree::TreeNode.new(:root)
140
+ ttroot << Tree::TreeNode.new(:item)
141
+ ttroot << Tree::TreeNode.new(:num)
142
+ ttroot << Tree::TreeNode.new(:site) << Tree::TreeNode.new(:url)
143
+ ttroot << Tree::TreeNode.new(:sonstiges)
144
+
145
+ # :singlechar
146
+ ttroot << Tree::TreeNode.new(:singlechar)
147
+ ttroot[:singlechar] << Tree::TreeNode.new(:struktur) << Tree::TreeNode.new(:punkt) << Tree::TreeNode.new(:satzende)
148
+ ttroot[:singlechar] << Tree::TreeNode.new(:minus)
149
+ ttroot[:singlechar] << Tree::TreeNode.new(:sonderzeichen)
150
+
151
+ # :item
152
+ ttroot[:item] << (wa_word=Tree::TreeNode.new(:de)) << Tree::TreeNode.new(:name)
153
+ wa_word << Tree::TreeNode.new(:abbrev)
154
+ wa_word << Tree::TreeNode.new(:multi)
155
+
156
+
157
+ DEF_TREE = ttroot
158
+ # see DEF_TREE.print_tree
159
+ end
160
+
161
+
162
+ see :item.to_fsymbol(DEF_TREE)
163
+ see :item.to_fsymbol(DEF_TREE)
164
+ see :singlechar.to_fsymbol(DEF_TREE)
165
+ see :singlechar.to_fsymbol(DEF_TREE)
166
+ see FSymbol.instance_cache
167
+
168
+
169
+
170
+ end
171
+
172
+
173
+
174
+
175
+
176
+
177
+
data/lib/kyanite.rb CHANGED
@@ -157,12 +157,32 @@
157
157
  # [Kyanite tests and examples]
158
158
  # [Usage] +require 'kyanite/general/callerutils'+
159
159
 
160
+ # @!macro [new] fsymbol
161
+ # === CallerUtils
162
+ # [Kyanite definitions] {FSymbol}
163
+ # [Kyanite tests and examples] {TestKyaniteFSymbols}
164
+ # [Usage] +require 'kyanite/fsymbol'+
165
+ #
166
+ # A {FSymbol} ("focusable Symbol") is
167
+ # a comparable {Symbol} within a hierarchy. You can use it for classifications.
168
+ # In its values​​, it is limited to the values​​,
169
+ # which are defined in the hierarchy.
170
+ # FSymbols are comparable with <= >= <=>. A more specific {FSymbol} is larger than a more general {FSymbol}
171
+ # (because the specific FSymbol contains more information)
172
+ # E.g. if you define a hierarchy if animal species, you can say:
173
+ # :insect.to_f_symbol <= :bee.to_f_symbol
174
+ # FSymbols are equal to Symbols with the same name.
175
+ #
176
+
177
+
178
+
160
179
  require 'drumherum'
161
180
 
162
181
  require 'kyanite/array'
163
182
  # require 'kyanite/basics' # Auswahl
164
183
  require 'kyanite/dictionary'
165
184
  require 'kyanite/enumerable'
185
+ require 'kyanite/fsymbol'
166
186
  require 'kyanite/general'
167
187
  require 'kyanite/hash'
168
188
  require 'kyanite/numeric'
data/test/_start_all.rb CHANGED
@@ -3,17 +3,10 @@
3
3
  # Führt alle Tests aus
4
4
  #
5
5
 
6
- if $0 == __FILE__
7
- require 'drumherum'
8
- smart_init
9
- end
6
+ require 'drumherum'
7
+ smart_init
10
8
 
11
- require 'transparent_nil'
12
-
13
-
14
- # Test-Verzeichnisse der Applikation
15
9
  Dir["#{File.join(Drumherum::directory_main, 'test')}/test_*.rb"].sort.each { |t| require t }
16
-
17
10
  Dir["#{File.join(Drumherum::directory_main, 'test', 'array' )}/test_*.rb"].sort.each { |t| require t }
18
11
  Dir["#{File.join(Drumherum::directory_main, 'test', 'enumerable' )}/test_*.rb"].sort.each { |t| require t }
19
12
  Dir["#{File.join(Drumherum::directory_main, 'test', 'general' )}/test_*.rb"].sort.each { |t| require t }
@@ -0,0 +1,122 @@
1
+ # ruby encoding: utf-8
2
+ # ü
3
+ if $0 == __FILE__
4
+ require 'drumherum'
5
+ smart_init
6
+ require 'perception'
7
+ end
8
+ require 'drumherum/unit_test'
9
+
10
+ require 'kyanite/fsymbol'
11
+
12
+
13
+ # @!macro fsymbol
14
+ class TestKyaniteFSymbols < UnitTest
15
+
16
+
17
+ def setup
18
+
19
+ unless defined? $def_tree
20
+ # Oberste Ebene
21
+ ttroot = Tree::TreeNode.new(:root)
22
+ ttroot << Tree::TreeNode.new(:item)
23
+ ttroot << Tree::TreeNode.new(:num)
24
+ ttroot << Tree::TreeNode.new(:site) << Tree::TreeNode.new(:url)
25
+ ttroot << Tree::TreeNode.new(:sonstiges)
26
+
27
+ # :singlechar
28
+ ttroot << Tree::TreeNode.new(:singlechar)
29
+ ttroot[:singlechar] << Tree::TreeNode.new(:struktur) << Tree::TreeNode.new(:punkt) << Tree::TreeNode.new(:satzende)
30
+ ttroot[:singlechar] << Tree::TreeNode.new(:minus)
31
+ ttroot[:singlechar] << Tree::TreeNode.new(:sonderzeichen)
32
+
33
+ # :item
34
+ ttroot[:item] << (wa_word=Tree::TreeNode.new(:de)) << Tree::TreeNode.new(:name)
35
+ wa_word << Tree::TreeNode.new(:abbrev)
36
+ wa_word << Tree::TreeNode.new(:multi)
37
+
38
+
39
+ $def_tree = ttroot
40
+ #$def_tree.print_tree
41
+ end
42
+
43
+ @tokencodes = [:num, :url, :site, :item, :punkt, :minus, :struktur, :sonderzeichen, :sonstiges, :singlechar, :satzende, :de, :abbrev, :name, :multi]
44
+ @root = :root.to_fsymbol($def_tree)
45
+ end
46
+
47
+
48
+
49
+ def test_first
50
+ a = FSymbol.new(:item)
51
+ assert_equal 'item', a.to_s
52
+ assert_equal ':item', a.inspect
53
+ end
54
+
55
+
56
+ def test_raise
57
+ assert_raise(ArgumentError) { FSymbol.new(:idfsdgtem) }
58
+ assert_raise(ArgumentError) { FSymbol.new('item') }
59
+ assert_raise(ArgumentError) { FSymbol.new(nil) }
60
+ end
61
+
62
+
63
+ def test_tokencodes
64
+ @tokencodes.each do |c|
65
+ assert_equal c.to_s, FSymbol.new(c).to_s, "FSymbol für Tokencode :#{c} konnte nicht erzeugt werden"
66
+ end
67
+ end
68
+
69
+
70
+ def test_all_child_keys
71
+ t = @tokencodes.to_set
72
+ b = FSymbol.new(:root).childs.to_set
73
+ diff = ((t-b) + (b-t)).to_a
74
+ assert_equal t, b, "\n\n\nDifferenz zwischen @tokencodes hier im Test und dem Definitionsbaum. \nUnterschied: #{diff}\n\n\n"
75
+ end
76
+
77
+
78
+ def test_root
79
+ assert_equal 0, @root <=> @root
80
+ assert_equal 0, @root <=> :root
81
+ assert @root >= @root
82
+ assert @root <= @root
83
+ assert @root >= @root
84
+ assert @root <= @root
85
+ @tokencodes.each do |c|
86
+ cf = c.to_fsymbol
87
+ assert_equal( -1, (@root <=> c.to_fsymbol ))
88
+ assert_equal( 1, (cf <=> @root ))
89
+ assert_equal( -1, (@root <=> cf ))
90
+ end
91
+ end
92
+
93
+
94
+ def test_specific
95
+ assert :item.to_fsymbol <= :name.to_fsymbol
96
+ assert :name.to_fsymbol >= :item.to_fsymbol
97
+ assert :item.to_fsymbol <= :abbrev.to_fsymbol
98
+ assert :abbrev.to_fsymbol >= :item.to_fsymbol
99
+ assert :minus.to_fsymbol >= :singlechar.to_fsymbol
100
+ assert :singlechar.to_fsymbol <= :minus.to_fsymbol
101
+ end
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+ end
118
+
119
+
120
+
121
+
122
+
data/version.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Kyanite
4
4
 
5
- VERSION = '0.7.4'
5
+ VERSION = '0.7.5'
6
6
 
7
7
  end
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kyanite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
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-11-12 00:00:00.000000000 Z
12
+ date: 2012-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: drumherum
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.1.19
21
+ version: 0.1.34
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.1.19
29
+ version: 0.1.34
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: transparent_nil
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: 0.1.7
37
+ version: 0.1.20
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: 0.1.7
45
+ version: 0.1.20
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: activesupport
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -202,6 +202,7 @@ files:
202
202
  - lib/kyanite/enumerable/enumerable_numerics.rb
203
203
  - lib/kyanite/enumerable/enumerable_strings.rb
204
204
  - lib/kyanite/enumerable/structure.rb
205
+ - lib/kyanite/fsymbol.rb
205
206
  - lib/kyanite/general.rb
206
207
  - lib/kyanite/general/callerutils.rb
207
208
  - lib/kyanite/general/classutils.rb
@@ -248,6 +249,7 @@ files:
248
249
  - test/string/test_nested.rb
249
250
  - test/string/test_split.rb
250
251
  - test/test_dictionary.rb
252
+ - test/test_fsymbol.rb
251
253
  - test/test_hash.rb
252
254
  - test/test_optimizer.rb
253
255
  - test/test_range.rb
@@ -298,6 +300,7 @@ test_files:
298
300
  - test/string/test_nested.rb
299
301
  - test/string/test_split.rb
300
302
  - test/test_dictionary.rb
303
+ - test/test_fsymbol.rb
301
304
  - test/test_hash.rb
302
305
  - test/test_optimizer.rb
303
306
  - test/test_range.rb