kxi 1.0.1 → 1.0.2

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.
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
@@ -1,26 +1,37 @@
1
- # Created by Matyáš Pokorný on 2018-01-24.
2
-
3
- module KXI
4
- module Exceptions
5
- class ConfigurationException < Exception
6
- def file
7
- @file
8
- end
9
-
10
- def path
11
- @path
12
- end
13
-
14
- def error_message
15
- @msg
16
- end
17
-
18
- def initialize(file, path, msg = nil)
19
- super("Invalid configuration <#{path}> in file '#{file}'!#{msg != nil ? ": #{msg}" : ''}")
20
- @file = file
21
- @path = path
22
- @msg = msg
23
- end
24
- end
25
- end
1
+ # Created by Matyáš Pokorný on 2018-01-24.
2
+
3
+ module KXI
4
+ module Exceptions
5
+ # Raised on error during configuration file reading
6
+ class ConfigurationException < Exception
7
+ # Gets the path of the configuration file
8
+ # @return [string] Path of the configuration file
9
+ def file
10
+ @file
11
+ end
12
+
13
+ # Gets the path of the configuration parameter
14
+ # @return [string] Path of the configuration parameter
15
+ def path
16
+ @path
17
+ end
18
+
19
+ # Gets the message of error
20
+ # @return [string] Message of error
21
+ def error_message
22
+ @msg
23
+ end
24
+
25
+ # Instantiates the {KXI::Exceptions::ConfigurationException} class
26
+ # @param [string] file Path of the configuration file
27
+ # @param [string] path Path of the configuration parameter
28
+ # @param [string,nil] msg Message of error
29
+ def initialize(file, path, msg = nil)
30
+ super("Invalid configuration <#{path}> in file '#{file}'!#{msg != nil ? ": #{msg}" : ''}")
31
+ @file = file
32
+ @path = path
33
+ @msg = msg
34
+ end
35
+ end
36
+ end
26
37
  end
@@ -0,0 +1,29 @@
1
+ # Created by Matyáš Pokorný on 2018-04-14.
2
+
3
+ module KXI
4
+ module Exceptions
5
+ # Raised when matrices or vectors are of incompatible dimensions during operation
6
+ class DimensionMismatchException < Exception
7
+ # Gets the expected dimension
8
+ # @return [integer] Expected dimension
9
+ def expected
10
+ @ex
11
+ end
12
+
13
+ # Gets the actual dimension
14
+ # @return [integer] Actual dimension
15
+ def actual
16
+ @act
17
+ end
18
+
19
+ # Instantiates the {KXI::Exceptions::DimensionMismatchException} class
20
+ # @param [integer] act Actual dimension
21
+ # @param [integer] ex Expected dimension
22
+ def initialize(act, ex)
23
+ @act = act
24
+ @ex = ex
25
+ super("Expected dimension #{ex} got #{act}!")
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,33 +1,33 @@
1
- # Created by Matyáš Pokorný on 2017-12-30.
2
-
3
- module KXI
4
- module Exceptions
5
- # Raised when some value is of unexpected type
6
- class InvalidTypeException < Exception
7
- # Returns expected types
8
- # @return [Array<Class>] Expected types
9
- def expected
10
- @exp
11
- end
12
-
13
- # Returns actual type
14
- # @return [Class] Actual type
15
- def actual
16
- @act
17
- end
18
-
19
- # Instantiates the [KXI::Exceptions::InvalidTypeException] class
20
- # @param exp [Array<Class>] Expected types
21
- # @param act [Class] Actual type
22
- def initialize(act, *exp)
23
- if exp.length == 1
24
- super("Value is of unexpected type! Expected <#{exp[0].name}> got <#{act.name}>")
25
- else
26
- super("Value is of unexpected type! Expected { #{exp.collect {|i| "<#{i}>"}.join(', ')} } got <#{act.name}>")
27
- end
28
- @exp = exp
29
- @act = act
30
- end
31
- end
32
- end
1
+ # Created by Matyáš Pokorný on 2017-12-30.
2
+
3
+ module KXI
4
+ module Exceptions
5
+ # Raised when some value is of unexpected type
6
+ class InvalidTypeException < Exception
7
+ # Returns expected types
8
+ # @return [Array<Class>] Expected types
9
+ def expected
10
+ @exp
11
+ end
12
+
13
+ # Returns actual type
14
+ # @return [Class] Actual type
15
+ def actual
16
+ @act
17
+ end
18
+
19
+ # Instantiates the [KXI::Exceptions::InvalidTypeException] class
20
+ # @param exp [Array<Class>] Expected types
21
+ # @param act [Class] Actual type
22
+ def initialize(act, *exp)
23
+ if exp.length == 1
24
+ super("Value is of unexpected type! Expected <#{exp[0].name}> got <#{act.name}>")
25
+ else
26
+ super("Value is of unexpected type! Expected { #{exp.collect {|i| "<#{i}>"}.join(', ')} } got <#{act.name}>")
27
+ end
28
+ @exp = exp
29
+ @act = act
30
+ end
31
+ end
32
+ end
33
33
  end
@@ -1,21 +1,21 @@
1
- # Created by Matyáš Pokorný on 2018-01-21.
2
-
3
- module KXI
4
- module Exceptions
5
- # Raised when argument value has no binding argument
6
- class NoArgumentException < Exception
7
- # Gets the erroneous value
8
- # @return [String] Erroneous value
9
- def value
10
- @val
11
- end
12
-
13
- # Instantiates the {KXI::Exceptions::NoArgumentException} class
14
- # @param val [String] Erroneous value
15
- def initialize(val)
16
- super("Value '#{val}' has no argument to bind to!")
17
- @val = val
18
- end
19
- end
20
- end
1
+ # Created by Matyáš Pokorný on 2018-01-21.
2
+
3
+ module KXI
4
+ module Exceptions
5
+ # Raised when argument value has no binding argument
6
+ class NoArgumentException < Exception
7
+ # Gets the erroneous value
8
+ # @return [String] Erroneous value
9
+ def value
10
+ @val
11
+ end
12
+
13
+ # Instantiates the {KXI::Exceptions::NoArgumentException} class
14
+ # @param val [String] Erroneous value
15
+ def initialize(val)
16
+ super("Value '#{val}' has no argument to bind to!")
17
+ @val = val
18
+ end
19
+ end
20
+ end
21
21
  end
@@ -1,13 +1,13 @@
1
- # Created by Matyáš Pokorný on 2017-12-29.
2
-
3
- module KXI
4
- module Exceptions
5
- # Raised when given part of code isn't yet implemented
6
- class NotImplementedException < Exception
7
- # Instantiates the {KXI::Exceptions::NotImplementedException} class
8
- def initialize
9
- super('Code not implemented yet!')
10
- end
11
- end
12
- end
1
+ # Created by Matyáš Pokorný on 2017-12-29.
2
+
3
+ module KXI
4
+ module Exceptions
5
+ # Raised when given part of code isn't yet implemented
6
+ class NotImplementedException < Exception
7
+ # Instantiates the {KXI::Exceptions::NotImplementedException} class
8
+ def initialize
9
+ super('Code not implemented yet!')
10
+ end
11
+ end
12
+ end
13
13
  end
@@ -1,44 +1,44 @@
1
- # Created by Matyáš Pokorný on 2017-12-29.
2
-
3
- module KXI
4
- module Exceptions
5
- # Raised when certain value is out of range
6
- class OutOfRangeException < Exception
7
- # Returns erroneous value
8
- # @return [Object] Erroneous value
9
- def value
10
- @val
11
- end
12
-
13
- # Returns minimal expected value
14
- # @return [Object, nil] Minimal expected value; nil if there is no minimum
15
- def minimum
16
- @min
17
- end
18
-
19
- # Returns maximal expected value
20
- # @return [Object, nil] Maximal expected value; nil if there is no maximum
21
- def maximum
22
- @max
23
- end
24
-
25
- # Instantiates the {KXI::Exceptions::OutOfRangeException} class
26
- # @param val [Object] Erroneous value
27
- # @param min [Object, nil] Minimal expected value; nil if there is no minimum
28
- # @param max [Object, nil] Maximal expected value; nil if there is no maximum
29
- # @note If both min and max are nil, then range is empty set
30
- def initialize(val, min = nil, max = nil)
31
- if min == nil and max == nil
32
- super("Value '#{val}' is out of range {}!")
33
- elsif min == max
34
- super("Value '#{val}' is out of range {#{min}}!")
35
- else
36
- super("Value '#{val}' is out of range #{(min == nil ? '(-∞' : "<#{min}")};#{(max == nil ? '∞)' : "#{max}>")}!")
37
- end
38
- @val = val
39
- @min = min
40
- @max = max
41
- end
42
- end
43
- end
1
+ # Created by Matyáš Pokorný on 2017-12-29.
2
+
3
+ module KXI
4
+ module Exceptions
5
+ # Raised when certain value is out of range
6
+ class OutOfRangeException < Exception
7
+ # Returns erroneous value
8
+ # @return [Object] Erroneous value
9
+ def value
10
+ @val
11
+ end
12
+
13
+ # Returns minimal expected value
14
+ # @return [Object, nil] Minimal expected value; nil if there is no minimum
15
+ def minimum
16
+ @min
17
+ end
18
+
19
+ # Returns maximal expected value
20
+ # @return [Object, nil] Maximal expected value; nil if there is no maximum
21
+ def maximum
22
+ @max
23
+ end
24
+
25
+ # Instantiates the {KXI::Exceptions::OutOfRangeException} class
26
+ # @param val [Object] Erroneous value
27
+ # @param min [Object, nil] Minimal expected value; nil if there is no minimum
28
+ # @param max [Object, nil] Maximal expected value; nil if there is no maximum
29
+ # @note If both min and max are nil, then range is empty set
30
+ def initialize(val, min = nil, max = nil)
31
+ if min == nil and max == nil
32
+ super("Value '#{val}' is out of range {}!")
33
+ elsif min == max
34
+ super("Value '#{val}' is out of range {#{min}}!")
35
+ else
36
+ super("Value '#{val}' is out of range #{(min == nil ? '(-∞' : "<#{min}")};#{(max == nil ? '∞)' : "#{max}>")}!")
37
+ end
38
+ @val = val
39
+ @min = min
40
+ @max = max
41
+ end
42
+ end
43
+ end
44
44
  end
@@ -1,21 +1,29 @@
1
- # Created by Matyáš Pokorný on 2018-01-27.
2
-
3
- module KXI
4
- module Exceptions
5
- class ParseException < Exception
6
- def value
7
- @val
8
- end
9
-
10
- def parser
11
- @par
12
- end
13
-
14
- def initialize(parser, val)
15
- super("Failed to parse value '#{val.to_s}' as #{parser}!")
16
- @par = parser
17
- @val = val
18
- end
19
- end
20
- end
1
+ # Created by Matyáš Pokorný on 2018-01-27.
2
+
3
+ module KXI
4
+ module Exceptions
5
+ # Raised when parser encounters an error
6
+ class ParseException < Exception
7
+ # Get the parsed value
8
+ # @return [any] Parsed value
9
+ def value
10
+ @val
11
+ end
12
+
13
+ # Gets the name of the parser
14
+ # @return [string] Name of the parser
15
+ def parser
16
+ @par
17
+ end
18
+
19
+ # Instantiates the {KXI::Exceptions::ParseException} class
20
+ # @param [string] parser Name of the parser
21
+ # @param [any] val Parsed value
22
+ def initialize(parser, val)
23
+ super("Failed to parse value '#{val.to_s}' as #{parser}!")
24
+ @par = parser
25
+ @val = val
26
+ end
27
+ end
28
+ end
21
29
  end
@@ -1,21 +1,21 @@
1
- # Created by Matyáš Pokorný on 2018-01-21.
2
-
3
- module KXI
4
- module Exceptions
5
- # Raised when specific verb was expected
6
- class VerbExpectedException < Exception
7
- # Gets array of verbs that were expected
8
- # @return [Array<String>] Expected verbs
9
- def verbs
10
- @verbs
11
- end
12
-
13
- # Instantiates the {KXI::CLI::VerbExpectedException} class
14
- # @param verbs [Array<String>] Expected verbs
15
- def initialize(verbs)
16
- super("Expected verb! (#{verbs.join(', ')})")
17
- @verbs = verbs
18
- end
19
- end
20
- end
1
+ # Created by Matyáš Pokorný on 2018-01-21.
2
+
3
+ module KXI
4
+ module Exceptions
5
+ # Raised when specific verb was expected
6
+ class VerbExpectedException < Exception
7
+ # Gets array of verbs that were expected
8
+ # @return [Array<String>] Expected verbs
9
+ def verbs
10
+ @verbs
11
+ end
12
+
13
+ # Instantiates the {KXI::CLI::VerbExpectedException} class
14
+ # @param verbs [Array<String>] Expected verbs
15
+ def initialize(verbs)
16
+ super("Expected verb! (#{verbs.join(', ')})")
17
+ @verbs = verbs
18
+ end
19
+ end
20
+ end
21
21
  end
@@ -0,0 +1,21 @@
1
+ # Created by Matyáš Pokorný on 2018-03-23.
2
+
3
+ module KXI
4
+ module Exceptions
5
+ # Raised when part of workspace path is a file
6
+ class WorkspaceCollisionException < Exception
7
+ # Gets the path of workspace
8
+ # @return [string] Path of workspace
9
+ def path
10
+ @path
11
+ end
12
+
13
+ # Instantiates the {KXI::Exceptions::WorkspaceCollisionException} class
14
+ # @param [string] path Path of workspace
15
+ def initialize(path)
16
+ super("Workspace path '#{path}' is used by file!")
17
+ @path = path
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,45 @@
1
+ # Created by Matyáš Pokorný on 2018-04-12.
2
+
3
+ module KXI
4
+ module Math
5
+ # Computes factorial
6
+ # @param [Integer] n Factorial base
7
+ # @return [Integer] Value of factorial
8
+ def self.fact(n)
9
+ n <= 0 ? 1 : n * fact(n - 1)
10
+ end
11
+
12
+ def self.lfact(n, l)
13
+ return (l == 1 or n <= 0) ? n : n * lfact(n - 1, l - 1)
14
+ end
15
+
16
+ # Computes fraction of factorials (!n / !m)
17
+ # @param [Integer] n Factorial base of numerator
18
+ # @param [Integer] m Factorial base of denominator
19
+ # @return [Numeric] Result of fraction
20
+ def self.pfact(n, m)
21
+ return 1 if n == m
22
+ return (1.to_f / lfact(m, m - n)) if m > n
23
+ return lfact(n, n - m)
24
+ end
25
+
26
+ # Computes the binomial coefficient
27
+ # @param [Integer] n First (upper) term of coefficient
28
+ # @param [Integer] k Second (lower) term of coefficient
29
+ # @return [Numeric] Binomial coefficient (n choose k)
30
+ def self.choose(n, k)
31
+ return pfact(n, k) / fact(n - k)
32
+ end
33
+
34
+ # Computes the permutation of two numbers
35
+ # @param [Integer] n First term of permutation
36
+ # @param [Integer] k Second term of permutation
37
+ # @return [Numeric] Permutation (k-permutations of n)
38
+ def self.permutation(n, k)
39
+ return 0 if k > n
40
+ pfact(n, n - k)
41
+ end
42
+
43
+ private_class_method :lfact
44
+ end
45
+ end