kxi 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/lib/kxi.rb +44 -39
  3. data/lib/kxi/application/config.rb +177 -177
  4. data/lib/kxi/application/config_reader.rb +16 -16
  5. data/lib/kxi/application/event.rb +35 -35
  6. data/lib/kxi/application/logger.rb +155 -155
  7. data/lib/kxi/application/version.rb +106 -74
  8. data/lib/kxi/application/version_expression.rb +94 -69
  9. data/lib/kxi/application/workspace.rb +105 -0
  10. data/lib/kxi/cli/anonymous_argument.rb +50 -50
  11. data/lib/kxi/cli/argument.rb +56 -56
  12. data/lib/kxi/cli/argument_values.rb +83 -83
  13. data/lib/kxi/cli/explicit_argument.rb +38 -38
  14. data/lib/kxi/cli/flag_argument.rb +15 -15
  15. data/lib/kxi/cli/named_argument.rb +59 -59
  16. data/lib/kxi/cli/property_list.rb +57 -48
  17. data/lib/kxi/cli/table.rb +82 -62
  18. data/lib/kxi/cli/verb.rb +282 -280
  19. data/lib/kxi/collections/array_collection.rb +106 -106
  20. data/lib/kxi/collections/enumerable.rb +527 -527
  21. data/lib/kxi/collections/enumerator.rb +31 -31
  22. data/lib/kxi/collections/hash_collection.rb +100 -100
  23. data/lib/kxi/collections/protected_collection.rb +20 -19
  24. data/lib/kxi/exceptions/abstract_exception.rb +34 -34
  25. data/lib/kxi/exceptions/argument_exception.rb +21 -21
  26. data/lib/kxi/exceptions/collection_exception.rb +13 -13
  27. data/lib/kxi/exceptions/configuration_exception.rb +36 -25
  28. data/lib/kxi/exceptions/dimension_mismatch_exception.rb +29 -0
  29. data/lib/kxi/exceptions/invalid_type_exception.rb +32 -32
  30. data/lib/kxi/exceptions/no_argument_exception.rb +20 -20
  31. data/lib/kxi/exceptions/not_implemented_exception.rb +12 -12
  32. data/lib/kxi/exceptions/out_of_range_exception.rb +43 -43
  33. data/lib/kxi/exceptions/parse_exception.rb +28 -20
  34. data/lib/kxi/exceptions/verb_expected_exception.rb +20 -20
  35. data/lib/kxi/exceptions/workspace_collision_exception.rb +21 -0
  36. data/lib/kxi/math/math.rb +45 -0
  37. data/lib/kxi/math/matrix.rb +303 -0
  38. data/lib/kxi/math/polynomial.rb +141 -101
  39. data/lib/kxi/math/vector.rb +181 -0
  40. data/lib/kxi/platform.rb +103 -57
  41. data/lib/kxi/reflection/stack_frame.rb +80 -80
  42. data/lib/kxi/version.rb +4 -4
  43. metadata +8 -3
  44. data/lib/kxi/exceptions/invalid_operation_exception.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78e859a6e89e40dbab305b79851a257dfd2ddf68
4
- data.tar.gz: aedb9bc1385418141e79d90d64fe688c00e529d4
3
+ metadata.gz: 98e721321d505ffda5f3bbcddb0f0433daa2c077
4
+ data.tar.gz: 0a2738b5d2f2a1f2936933049e91b14042ab031a
5
5
  SHA512:
6
- metadata.gz: 856340dde06a8e744284dfb3060eb69a053f90868338ce3b7034163750c566f8c0f60cbc67c59b73ee0c9666b18cbe1e808afcb22d84cba58a0f49593c5517ce
7
- data.tar.gz: 10ee0e919f19ea968f65220714bc2a5be7a42cc4f2d59999c40b5c02ab0300da8974c54b814b977b9e7ff7cd86c2df0a7137e9110066169c499f618cf64b3702
6
+ metadata.gz: 5051a6a876e67ff3a17df12a360f1fbede25a96303c49cbe5db66b12630e1a8ae5461294fff18a8a24138f903eac4d1912ca5c6659aab11d31451bc950d96e60
7
+ data.tar.gz: 8708c3aa97d4efd7e44d8385ca445c6e79ee73e5a9f1f8bbbb9e441cde0170cfabfeaf7f358a6604c55e8d48aef2b30d4b0fecea4f5bd1c041ee2029a6c61732
data/lib/kxi.rb CHANGED
@@ -1,39 +1,44 @@
1
- # Ruby
2
- require 'date'
3
-
4
- # KXI
5
- require 'kxi/version'
6
- require 'kxi/exceptions/abstract_exception'
7
- require 'kxi/exceptions/collection_exception'
8
- require 'kxi/exceptions/out_of_range_exception'
9
- require 'kxi/exceptions/not_implemented_exception'
10
- require 'kxi/exceptions/argument_exception'
11
- require 'kxi/exceptions/no_argument_exception'
12
- require 'kxi/exceptions/verb_expected_exception'
13
- require 'kxi/exceptions/invalid_type_exception'
14
- require 'kxi/exceptions/configuration_exception'
15
- require 'kxi/exceptions/parse_exception'
16
- require 'kxi/exceptions/invalid_operation_exception'
17
- require 'kxi/reflection/stack_frame'
18
- require 'kxi/collections/enumerator'
19
- require 'kxi/collections/enumerable'
20
- require 'kxi/collections/array_collection'
21
- require 'kxi/collections/hash_collection'
22
- require 'kxi/collections/protected_collection'
23
- require 'kxi/cli/argument'
24
- require 'kxi/cli/explicit_argument'
25
- require 'kxi/cli/anonymous_argument'
26
- require 'kxi/cli/flag_argument'
27
- require 'kxi/cli/named_argument'
28
- require 'kxi/cli/argument_values'
29
- require 'kxi/cli/verb'
30
- require 'kxi/cli/table'
31
- require 'kxi/cli/property_list'
32
- require 'kxi/application/config_reader'
33
- require 'kxi/application/config'
34
- require 'kxi/application/event'
35
- require 'kxi/application/logger'
36
- require 'kxi/application/version'
37
- require 'kxi/application/version_expression'
38
- require 'kxi/math/polynomial'
39
- require 'kxi/platform'
1
+ # Ruby
2
+ require 'date'
3
+
4
+ # KXI
5
+ require 'kxi/version'
6
+ require 'kxi/platform'
7
+ require 'kxi/exceptions/abstract_exception'
8
+ require 'kxi/exceptions/collection_exception'
9
+ require 'kxi/exceptions/out_of_range_exception'
10
+ require 'kxi/exceptions/not_implemented_exception'
11
+ require 'kxi/exceptions/argument_exception'
12
+ require 'kxi/exceptions/no_argument_exception'
13
+ require 'kxi/exceptions/verb_expected_exception'
14
+ require 'kxi/exceptions/invalid_type_exception'
15
+ require 'kxi/exceptions/configuration_exception'
16
+ require 'kxi/exceptions/parse_exception'
17
+ require 'kxi/exceptions/workspace_collision_exception'
18
+ require 'kxi/exceptions/dimension_mismatch_exception'
19
+ require 'kxi/reflection/stack_frame'
20
+ require 'kxi/collections/enumerator'
21
+ require 'kxi/collections/enumerable'
22
+ require 'kxi/collections/array_collection'
23
+ require 'kxi/collections/hash_collection'
24
+ require 'kxi/collections/protected_collection'
25
+ require 'kxi/cli/argument'
26
+ require 'kxi/cli/explicit_argument'
27
+ require 'kxi/cli/anonymous_argument'
28
+ require 'kxi/cli/flag_argument'
29
+ require 'kxi/cli/named_argument'
30
+ require 'kxi/cli/argument_values'
31
+ require 'kxi/cli/verb'
32
+ require 'kxi/cli/table'
33
+ require 'kxi/cli/property_list'
34
+ require 'kxi/application/config_reader'
35
+ require 'kxi/application/config'
36
+ require 'kxi/application/event'
37
+ require 'kxi/application/logger'
38
+ require 'kxi/application/version'
39
+ require 'kxi/application/version_expression'
40
+ require 'kxi/application/workspace'
41
+ require 'kxi/math/math'
42
+ require 'kxi/math/vector'
43
+ require 'kxi/math/matrix'
44
+ require 'kxi/math/polynomial'
@@ -1,178 +1,178 @@
1
- # Created by Matyáš Pokorný on 2018-01-24.
2
-
3
- module KXI
4
- module Application
5
- # Represents configuration file
6
- class Config
7
- # Gets configuration file
8
- # @return [String] Path to configuration file
9
- def file
10
- @file
11
- end
12
-
13
- # Instantiates the {KXI::Application::Config} file
14
- # @param file [String] Configuration file to read
15
- # @param reader [KXI::Application::ConfigReader] Readers used to parse configuration
16
- def initialize(file, reader)
17
- @file = file
18
- @obj = reader.parse(File.read(file))
19
- @pth = ''
20
- @def = false
21
- end
22
-
23
- # Gets current context
24
- # @return [Object] Current context
25
- def context
26
- @obj
27
- end
28
-
29
- # Gets path of current context
30
- # @return [String] Path of current context
31
- def path
32
- @pth
33
- end
34
-
35
- # Gets value or default from current context
36
- # @param key [String] Name of value
37
- # @param default [Object, nil] Default value
38
- # @yield [val] Validator function
39
- # @yieldparam val [Object, nil] Value to validate
40
- # @return [Object, nil] Value or default
41
- def get(key, default = nil, &validator)
42
- if not @def and @obj.key?(key)
43
- ctx = @obj[key]
44
- return ctx if validator == nil
45
- return validate(key, ctx, &validator)
46
- else
47
- return default
48
- end
49
- end
50
-
51
- # Gets value from current context
52
- # @param key [String] Name of value
53
- # @yield [val] Validator function
54
- # @yieldparam val [Object, nil] Value to validate
55
- # @return [Object, nil] Value
56
- # @raise [KXI::Exceptions::ConfigurationException] Raised when field is not found
57
- def get!(key, &validator)
58
- if not @def and @obj.key?(key)
59
- ctx = @obj[key]
60
- return ctx if validator == nil
61
- return validate(key, ctx, &validator)
62
- else
63
- raise(KXI::Exceptions::ConfigurationException.new(@file, "#{@pth}/#{key}", 'Field is mandatory!'))
64
- end
65
- end
66
-
67
- # Enters named section of configuration file
68
- # @param key [String] Name of section
69
- # @param man [Bool] Determines whether this section is mandatory
70
- # @yield [] Block of actions for entered context
71
- def inside(key, man = false, &block)
72
- if not @def and @obj.key?(key)
73
- ctx = @obj[key]
74
- raise(KXI::Exceptions::ConfigurationException.new(@file, "#{@pth}/#{key}", 'Field must be object!')) unless ctx.is_a?(Hash)
75
- enter(key, ctx) do
76
- block.call
77
- end
78
- elsif man
79
- raise(KXI::Exceptions::ConfigurationException.new(@file, "#{@pth}/#{key}", 'Object is mandatory!'))
80
- else
81
- enter(key, nil) do
82
- if @def
83
- block.call
84
- else
85
- @def = true
86
- block.call
87
- @def = false
88
- end
89
- end
90
- end
91
- end
92
-
93
- # Enters mandatory named section of configuration file
94
- # @param key [String] Name of section
95
- # @yield [] Block of actions for entered context
96
- def inside!(key, &block)
97
- inside(key, true) { block.call }
98
- end
99
-
100
- # Iterates through collection
101
- # @param key [String] Name of collection
102
- # @param man [Bool] Determines whether this section is mandatory
103
- # @yield [] Block of actions for entered context
104
- def each_index(key, man = false, &block)
105
- if not @def and @obj.key?(key)
106
- ctx = @obj[key]
107
- raise(KXI::Exceptions::ConfigurationException.new(@file, "#{@pth}/#{key}", 'Field must be array!')) unless ctx.is_a?(Array)
108
- ctx.each_with_index do |itm, idx|
109
- enter("#{key}[#{idx}]", itm) do
110
- block.call
111
- end
112
- end
113
- elsif man
114
- raise(KXI::Exceptions::ConfigurationException.new(@file, "#{@pth}/#{key}", 'Array is mandatory!'))
115
- end
116
- end
117
-
118
- # Iterates through mandatory collection
119
- # @param key [String] Name of collection
120
- # @yield [] Block of actions for entered context
121
- def each_index!(key, &block)
122
- each_index(key, true) { block.call }
123
- end
124
-
125
- # Iterates through fields of object
126
- # @param key [String] Name of object
127
- # @param man [Bool] Determines whether this section is mandatory
128
- # @yield [idx] Block of actions for entered context
129
- # @yieldparam idx [String] Name of field
130
- def each_field(key, man = false, &block)
131
- if not @def and @obj.key?(key)
132
- ctx = @obj[key]
133
- raise(KXI::Exceptions::ConfigurationException.new(@file, "#{@pth}/#{key}", 'Field must be object!')) unless ctx.is_a?(Hash)
134
- ctx.each_pair do |idx, itm|
135
- enter("#{key}/#{idx}", itm) do
136
- block.call(idx)
137
- end
138
- end
139
- elsif man
140
- raise(KXI::Exceptions::ConfigurationException.new(@file, "#{@pth}/#{key}", 'Object is mandatory!'))
141
- end
142
- end
143
-
144
- # Iterates through fields of mandatory object
145
- # @param key [String] Name of object
146
- # @yield [idx] Block of actions for entered context
147
- # @yieldparam idx [String] Name of field
148
- def each_field!(key, &block)
149
- each_field(key, true) { |itm| block.call(itm) }
150
- end
151
-
152
- def enter(key, ctx, &block)
153
- obj = @obj
154
- pth = @pth
155
- @obj = ctx
156
- @pth = "#{@pth}/#{key}"
157
- block.call
158
- ensure
159
- @pth = pth
160
- @obj = obj
161
- end
162
-
163
- def validate(key, ctx, &validator)
164
- begin
165
- enter(key, ctx) do
166
- validator.call(ctx)
167
- end
168
- return ctx
169
- rescue Exception => ex
170
- raise(KXI::Exceptions::ConfigurationException.new(@file, "#{@pth}/#{key}", ex.message))
171
- end
172
- end
173
-
174
- protected :context, :path, :get, :get!, :inside, :inside!, :each_index, :each_index!, :each_field, :each_field!
175
- private :enter, :validate
176
- end
177
- end
1
+ # Created by Matyáš Pokorný on 2018-01-24.
2
+
3
+ module KXI
4
+ module Application
5
+ # Represents configuration file
6
+ class Config
7
+ # Gets configuration file
8
+ # @return [String] Path to configuration file
9
+ def file
10
+ @file
11
+ end
12
+
13
+ # Instantiates the {KXI::Application::Config} file
14
+ # @param file [String] Configuration file to read
15
+ # @param reader [KXI::Application::ConfigReader] Readers used to parse configuration
16
+ def initialize(file, reader)
17
+ @file = file
18
+ @obj = reader.parse(File.read(file))
19
+ @pth = ''
20
+ @def = false
21
+ end
22
+
23
+ # Gets current context
24
+ # @return [Object] Current context
25
+ def context
26
+ @obj
27
+ end
28
+
29
+ # Gets path of current context
30
+ # @return [String] Path of current context
31
+ def path
32
+ @pth
33
+ end
34
+
35
+ # Gets value or default from current context
36
+ # @param key [String] Name of value
37
+ # @param default [Object, nil] Default value
38
+ # @yield [val] Validator function
39
+ # @yieldparam val [Object, nil] Value to validate
40
+ # @return [Object, nil] Value or default
41
+ def get(key, default = nil, &validator)
42
+ if not @def and @obj.key?(key)
43
+ ctx = @obj[key]
44
+ return ctx if validator == nil
45
+ return validate(key, ctx, &validator)
46
+ else
47
+ return default
48
+ end
49
+ end
50
+
51
+ # Gets value from current context
52
+ # @param key [String] Name of value
53
+ # @yield [val] Validator function
54
+ # @yieldparam val [Object, nil] Value to validate
55
+ # @return [Object, nil] Value
56
+ # @raise [KXI::Exceptions::ConfigurationException] Raised when field is not found
57
+ def get!(key, &validator)
58
+ if not @def and @obj.key?(key)
59
+ ctx = @obj[key]
60
+ return ctx if validator == nil
61
+ return validate(key, ctx, &validator)
62
+ else
63
+ raise(KXI::Exceptions::ConfigurationException.new(@file, "#{@pth}/#{key}", 'Field is mandatory!'))
64
+ end
65
+ end
66
+
67
+ # Enters named section of configuration file
68
+ # @param key [String] Name of section
69
+ # @param man [Bool] Determines whether this section is mandatory
70
+ # @yield [] Block of actions for entered context
71
+ def inside(key, man = false, &block)
72
+ if not @def and @obj.key?(key)
73
+ ctx = @obj[key]
74
+ raise(KXI::Exceptions::ConfigurationException.new(@file, "#{@pth}/#{key}", 'Field must be object!')) unless ctx.is_a?(Hash)
75
+ enter(key, ctx) do
76
+ block.call
77
+ end
78
+ elsif man
79
+ raise(KXI::Exceptions::ConfigurationException.new(@file, "#{@pth}/#{key}", 'Object is mandatory!'))
80
+ else
81
+ enter(key, nil) do
82
+ if @def
83
+ block.call
84
+ else
85
+ @def = true
86
+ block.call
87
+ @def = false
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ # Enters mandatory named section of configuration file
94
+ # @param key [String] Name of section
95
+ # @yield [] Block of actions for entered context
96
+ def inside!(key, &block)
97
+ inside(key, true) { block.call }
98
+ end
99
+
100
+ # Iterates through collection
101
+ # @param key [String] Name of collection
102
+ # @param man [Bool] Determines whether this section is mandatory
103
+ # @yield [] Block of actions for entered context
104
+ def each_index(key, man = false, &block)
105
+ if not @def and @obj.key?(key)
106
+ ctx = @obj[key]
107
+ raise(KXI::Exceptions::ConfigurationException.new(@file, "#{@pth}/#{key}", 'Field must be array!')) unless ctx.is_a?(Array)
108
+ ctx.each_with_index do |itm, idx|
109
+ enter("#{key}[#{idx}]", itm) do
110
+ block.call
111
+ end
112
+ end
113
+ elsif man
114
+ raise(KXI::Exceptions::ConfigurationException.new(@file, "#{@pth}/#{key}", 'Array is mandatory!'))
115
+ end
116
+ end
117
+
118
+ # Iterates through mandatory collection
119
+ # @param key [String] Name of collection
120
+ # @yield [] Block of actions for entered context
121
+ def each_index!(key, &block)
122
+ each_index(key, true) { block.call }
123
+ end
124
+
125
+ # Iterates through fields of object
126
+ # @param key [String] Name of object
127
+ # @param man [Bool] Determines whether this section is mandatory
128
+ # @yield [idx] Block of actions for entered context
129
+ # @yieldparam idx [String] Name of field
130
+ def each_field(key, man = false, &block)
131
+ if not @def and @obj.key?(key)
132
+ ctx = @obj[key]
133
+ raise(KXI::Exceptions::ConfigurationException.new(@file, "#{@pth}/#{key}", 'Field must be object!')) unless ctx.is_a?(Hash)
134
+ ctx.each_pair do |idx, itm|
135
+ enter("#{key}/#{idx}", itm) do
136
+ block.call(idx)
137
+ end
138
+ end
139
+ elsif man
140
+ raise(KXI::Exceptions::ConfigurationException.new(@file, "#{@pth}/#{key}", 'Object is mandatory!'))
141
+ end
142
+ end
143
+
144
+ # Iterates through fields of mandatory object
145
+ # @param key [String] Name of object
146
+ # @yield [idx] Block of actions for entered context
147
+ # @yieldparam idx [String] Name of field
148
+ def each_field!(key, &block)
149
+ each_field(key, true) { |itm| block.call(itm) }
150
+ end
151
+
152
+ def enter(key, ctx, &block)
153
+ obj = @obj
154
+ pth = @pth
155
+ @obj = ctx
156
+ @pth = "#{@pth}/#{key}"
157
+ block.call
158
+ ensure
159
+ @pth = pth
160
+ @obj = obj
161
+ end
162
+
163
+ def validate(key, ctx, &validator)
164
+ begin
165
+ enter(key, ctx) do
166
+ validator.call(ctx)
167
+ end
168
+ return ctx
169
+ rescue Exception => ex
170
+ raise(KXI::Exceptions::ConfigurationException.new(@file, "#{@pth}/#{key}", ex.message))
171
+ end
172
+ end
173
+
174
+ protected :context, :path, :get, :get!, :inside, :inside!, :each_index, :each_index!, :each_field, :each_field!
175
+ private :enter, :validate
176
+ end
177
+ end
178
178
  end