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,17 +1,17 @@
1
- # Created by Matyáš Pokorný on 2018-01-24.
2
-
3
- module KXI
4
- module Application
5
- # Parses configuration
6
- # @abstract
7
- class ConfigReader
8
- # Parses configuration from file
9
- # @param str [String] Data to parse
10
- # @return [Hash] Parsed configuration
11
- # @abstract
12
- def parse(str)
13
- raise(KXI::Exceptions::AbstractException.new(KXI::Application::ConfigReader))
14
- end
15
- end
16
- end
1
+ # Created by Matyáš Pokorný on 2018-01-24.
2
+
3
+ module KXI
4
+ module Application
5
+ # Parses configuration
6
+ # @abstract
7
+ class ConfigReader
8
+ # Parses configuration from file
9
+ # @param str [String] Data to parse
10
+ # @return [Hash] Parsed configuration
11
+ # @abstract
12
+ def parse(str)
13
+ raise(KXI::Exceptions::AbstractException.new(KXI::Application::ConfigReader))
14
+ end
15
+ end
16
+ end
17
17
  end
@@ -1,36 +1,36 @@
1
- # Created by Matyáš Pokorný on 2018-01-26.
2
-
3
- module KXI
4
- module Application
5
- # Event handler
6
- class Event
7
- # Adds hook to handler
8
- # @return [Number] Id of hook
9
- # @yield [sender, *args] Action block of hook
10
- # @yieldparam sender [Object] Invoker of event
11
- # @yieldparam args [Array<Object, nil>] Arguments of invocation
12
- def add(&block)
13
- @hooks.push(block)
14
- return @hooks.length - 1
15
- end
16
-
17
- # Removes hook from handler
18
- # @param id [Number] Id of hook to remove
19
- def remove(id)
20
- @hooks.delete_at(id)
21
- end
22
-
23
- # Instantiates the {KXI::Application::Event} class
24
- def initialize
25
- @hooks = []
26
- end
27
-
28
- # Invokes all hooks
29
- # @param sender [Object] Invoker of event
30
- # @param args [Array<Object, nil>] Arguments of invocation
31
- def fire(sender, *args)
32
- @hooks.each { |h| h.call(sender, *args) }
33
- end
34
- end
35
- end
1
+ # Created by Matyáš Pokorný on 2018-01-26.
2
+
3
+ module KXI
4
+ module Application
5
+ # Event handler
6
+ class Event
7
+ # Adds hook to handler
8
+ # @return [Number] Id of hook
9
+ # @yield [sender, *args] Action block of hook
10
+ # @yieldparam sender [Object] Invoker of event
11
+ # @yieldparam args [Array<Object, nil>] Arguments of invocation
12
+ def add(&block)
13
+ @hooks.push(block)
14
+ return @hooks.length - 1
15
+ end
16
+
17
+ # Removes hook from handler
18
+ # @param id [Number] Id of hook to remove
19
+ def remove(id)
20
+ @hooks.delete_at(id)
21
+ end
22
+
23
+ # Instantiates the {KXI::Application::Event} class
24
+ def initialize
25
+ @hooks = []
26
+ end
27
+
28
+ # Invokes all hooks
29
+ # @param sender [Object] Invoker of event
30
+ # @param args [Array<Object, nil>] Arguments of invocation
31
+ def fire(sender, *args)
32
+ @hooks.each { |h| h.call(sender, *args) }
33
+ end
34
+ end
35
+ end
36
36
  end
@@ -1,156 +1,156 @@
1
- # Created by Matyáš Pokorný on 2018-01-26.
2
-
3
- module KXI
4
- module Application
5
- # Allows simple unstructured (time-independent) logging
6
- class Logger
7
- # Gets the message event
8
- # @return [KXI::Application::Event] Message event
9
- def on_message
10
- @event
11
- end
12
-
13
- # Attaches action to message event
14
- # @param min [KXI::Application::Logger::Message::Severity] Minimal severity of message
15
- # @yield [msg] Event action
16
- # @yieldparam msg [KXI::Application::Logger::Message] Logger message
17
- # @return [Number] Id of event hook
18
- def attach(min = Message::Severity::COMMAND, &block)
19
- return @event.add { |s, msg| block.call(msg) if msg.severity.level >= min.level }
20
- end
21
-
22
- # Instantiates the {KXI::Application::Logger} class
23
- def initialize
24
- @event = KXI::Application::Event.new
25
- @start = DateTime.now
26
- end
27
-
28
- # Logs message with the {KXI::Application::Logger::Message::Severity::COMMAND} severity
29
- # @param cmd [String] Executed command
30
- def command(cmd)
31
- log(Message::Severity::COMMAND, cmd)
32
- end
33
-
34
- # Logs message with the {KXI::Application::Logger::Message::Severity::TRACE} severity
35
- # @param msg [String] Text of message
36
- def trace(msg)
37
- log(Message::Severity::TRACE, msg)
38
- end
39
-
40
- # Logs message with the {KXI::Application::Logger::Message::Severity::DEBUG} severity
41
- # @param msg [String] Text of message
42
- def debug(msg)
43
- log(Message::Severity::DEBUG, msg)
44
- end
45
-
46
- # Logs message with the {KXI::Application::Logger::Message::Severity::INFO} severity
47
- # @param msg [String] Text of message
48
- def info(msg)
49
- log(Message::Severity::INFO, msg)
50
- end
51
-
52
- # Logs message with the {KXI::Application::Logger::Message::Severity::WARNING} severity
53
- # @param msg [String] Text of message
54
- def warning(msg)
55
- log(Message::Severity::WARNING, msg)
56
- end
57
-
58
- # Logs message with the {KXI::Application::Logger::Message::Severity::ERROR} severity
59
- # @param msg [String] Text of message
60
- def error(msg)
61
- log(Message::Severity::ERROR, msg)
62
- end
63
-
64
- # Logs message with the {KXI::Application::Logger::Message::Severity::FATAL} severity
65
- # @param msg [String] Text of message
66
- def fatal(msg)
67
- log(Message::Severity::FATAL, msg)
68
- end
69
-
70
- def log(severity, msg)
71
- now = DateTime.now
72
- @event.fire(self, Message.new(severity, now - @start, now, msg))
73
- end
74
-
75
- private :log
76
-
77
- # Represents a log message
78
- class Message
79
- # Represents severity of message
80
- class Severity
81
- # Gets the name of severity
82
- # @return [String] Name of severity
83
- def name
84
- @name
85
- end
86
-
87
- # Gets the level of severity
88
- # @return [Number] Level of severity
89
- def level
90
- @lvl
91
- end
92
-
93
- # Instantiates the [KXI::Application::Logger::Message::Severity] class
94
- # @param nm [String] Name of severity
95
- # @param lvl [Number] Level of severity
96
- def initialize(nm, lvl)
97
- @name = nm
98
- @lvl = lvl
99
- end
100
-
101
-
102
- # Severity of messages that log execution of external commands
103
- COMMAND = Severity.new('command', 0)
104
- # Severity of messages that allow tracing of execution paths
105
- TRACE = Severity.new('trace', 1)
106
- # Severity of messages used for debugging
107
- DEBUG = Severity.new('debug', 2)
108
- # Severity of messages that user should know about
109
- INFO = Severity.new('info', 3)
110
- # Severity of messages that notify about something that might lead in future to problems
111
- WARNING = Severity.new('warning', 4)
112
- # Severity of messages that notify about problems that application can recover from
113
- ERROR = Severity.new('error', 5)
114
- # Severity of messages that notify about problems that application cannot recover from
115
- FATAL = Severity.new('fatal', 6)
116
- end
117
-
118
- # Gets the severity of message
119
- # @return [KXI::Application::Logger::Message:Severity] Severity of message
120
- def severity
121
- @sev
122
- end
123
-
124
- # Gets time at which the message was created
125
- # @return [DateTime] Time of creation
126
- def absolute_time
127
- @ttime
128
- end
129
-
130
- # Gets time, relative to creation of logger, at which the message was created
131
- # @return [DateTime] Relative time of creation
132
- def relative_time
133
- @rtime
134
- end
135
-
136
- # Gets the text message
137
- # @return [String] Message
138
- def message
139
- @msg
140
- end
141
-
142
- # Instantiates the {KXI::Application::Logger::Message} class
143
- # @param severity [KXI::Application::Logger::Message::Severity] Severity of message
144
- # @param rtime [DateTime] Relative time of message
145
- # @param ttime [DateTime] Absolute time of message
146
- # @param message [String] Text of message
147
- def initialize(severity, rtime, ttime, message)
148
- @sev = severity
149
- @rtime = rtime
150
- @ttime = ttime
151
- @msg = message
152
- end
153
- end
154
- end
155
- end
1
+ # Created by Matyáš Pokorný on 2018-01-26.
2
+
3
+ module KXI
4
+ module Application
5
+ # Allows simple unstructured (time-independent) logging
6
+ class Logger
7
+ # Gets the message event
8
+ # @return [KXI::Application::Event] Message event
9
+ def on_message
10
+ @event
11
+ end
12
+
13
+ # Attaches action to message event
14
+ # @param min [KXI::Application::Logger::Message::Severity] Minimal severity of message
15
+ # @yield [msg] Event action
16
+ # @yieldparam msg [KXI::Application::Logger::Message] Logger message
17
+ # @return [Number] Id of event hook
18
+ def attach(min = Message::Severity::COMMAND, &block)
19
+ return @event.add { |s, msg| block.call(msg) if msg.severity.level >= min.level }
20
+ end
21
+
22
+ # Instantiates the {KXI::Application::Logger} class
23
+ def initialize
24
+ @event = KXI::Application::Event.new
25
+ @start = DateTime.now
26
+ end
27
+
28
+ # Logs message with the {KXI::Application::Logger::Message::Severity::COMMAND} severity
29
+ # @param cmd [String] Executed command
30
+ def command(cmd)
31
+ log(Message::Severity::COMMAND, cmd)
32
+ end
33
+
34
+ # Logs message with the {KXI::Application::Logger::Message::Severity::TRACE} severity
35
+ # @param msg [String] Text of message
36
+ def trace(msg)
37
+ log(Message::Severity::TRACE, msg)
38
+ end
39
+
40
+ # Logs message with the {KXI::Application::Logger::Message::Severity::DEBUG} severity
41
+ # @param msg [String] Text of message
42
+ def debug(msg)
43
+ log(Message::Severity::DEBUG, msg)
44
+ end
45
+
46
+ # Logs message with the {KXI::Application::Logger::Message::Severity::INFO} severity
47
+ # @param msg [String] Text of message
48
+ def info(msg)
49
+ log(Message::Severity::INFO, msg)
50
+ end
51
+
52
+ # Logs message with the {KXI::Application::Logger::Message::Severity::WARNING} severity
53
+ # @param msg [String] Text of message
54
+ def warning(msg)
55
+ log(Message::Severity::WARNING, msg)
56
+ end
57
+
58
+ # Logs message with the {KXI::Application::Logger::Message::Severity::ERROR} severity
59
+ # @param msg [String] Text of message
60
+ def error(msg)
61
+ log(Message::Severity::ERROR, msg)
62
+ end
63
+
64
+ # Logs message with the {KXI::Application::Logger::Message::Severity::FATAL} severity
65
+ # @param msg [String] Text of message
66
+ def fatal(msg)
67
+ log(Message::Severity::FATAL, msg)
68
+ end
69
+
70
+ def log(severity, msg)
71
+ now = DateTime.now
72
+ @event.fire(self, Message.new(severity, now - @start, now, msg))
73
+ end
74
+
75
+ private :log
76
+
77
+ # Represents a log message
78
+ class Message
79
+ # Represents severity of message
80
+ class Severity
81
+ # Gets the name of severity
82
+ # @return [String] Name of severity
83
+ def name
84
+ @name
85
+ end
86
+
87
+ # Gets the level of severity
88
+ # @return [Number] Level of severity
89
+ def level
90
+ @lvl
91
+ end
92
+
93
+ # Instantiates the [KXI::Application::Logger::Message::Severity] class
94
+ # @param nm [String] Name of severity
95
+ # @param lvl [Number] Level of severity
96
+ def initialize(nm, lvl)
97
+ @name = nm
98
+ @lvl = lvl
99
+ end
100
+
101
+
102
+ # Severity of messages that log execution of external commands
103
+ COMMAND = Severity.new('command', 0)
104
+ # Severity of messages that allow tracing of execution paths
105
+ TRACE = Severity.new('trace', 1)
106
+ # Severity of messages used for debugging
107
+ DEBUG = Severity.new('debug', 2)
108
+ # Severity of messages that user should know about
109
+ INFO = Severity.new('info', 3)
110
+ # Severity of messages that notify about something that might lead in future to problems
111
+ WARNING = Severity.new('warning', 4)
112
+ # Severity of messages that notify about problems that application can recover from
113
+ ERROR = Severity.new('error', 5)
114
+ # Severity of messages that notify about problems that application cannot recover from
115
+ FATAL = Severity.new('fatal', 6)
116
+ end
117
+
118
+ # Gets the severity of message
119
+ # @return [KXI::Application::Logger::Message:Severity] Severity of message
120
+ def severity
121
+ @sev
122
+ end
123
+
124
+ # Gets time at which the message was created
125
+ # @return [DateTime] Time of creation
126
+ def absolute_time
127
+ @ttime
128
+ end
129
+
130
+ # Gets time, relative to creation of logger, at which the message was created
131
+ # @return [DateTime] Relative time of creation
132
+ def relative_time
133
+ @rtime
134
+ end
135
+
136
+ # Gets the text message
137
+ # @return [String] Message
138
+ def message
139
+ @msg
140
+ end
141
+
142
+ # Instantiates the {KXI::Application::Logger::Message} class
143
+ # @param severity [KXI::Application::Logger::Message::Severity] Severity of message
144
+ # @param rtime [DateTime] Relative time of message
145
+ # @param ttime [DateTime] Absolute time of message
146
+ # @param message [String] Text of message
147
+ def initialize(severity, rtime, ttime, message)
148
+ @sev = severity
149
+ @rtime = rtime
150
+ @ttime = ttime
151
+ @msg = message
152
+ end
153
+ end
154
+ end
155
+ end
156
156
  end
@@ -1,75 +1,107 @@
1
- # Created by Matyáš Pokorný on 2018-01-27.
2
-
3
- module KXI
4
- module Application
5
- class Version
6
- def major
7
- @major
8
- end
9
-
10
- def minor
11
- @minor
12
- end
13
-
14
- def patch
15
- @patch
16
- end
17
-
18
- def identifier
19
- @id
20
- end
21
-
22
- def metadata
23
- @meta
24
- end
25
-
26
- def initialize(major, minor = 0, patch = 0, id = nil, meta = nil)
27
- @major = major
28
- @minor = minor
29
- @patch = patch
30
- @id = id
31
- @meta = meta
32
- end
33
-
34
- def to_s
35
- "#{@major}.#{@minor}.#{@patch}#{@id == nil ? '' : "-#{@id}"}#{@meta == nil ? '' : "+#{@meta}"}"
36
- end
37
-
38
- def ==(other)
39
- return false unless other.is_a?(KXI::Application::Version)
40
- return (@major == other.major and @minor == other.minor and @patch == other.patch and @id == other.identifier)
41
- end
42
-
43
- def <(other)
44
- raise(KXI::Exceptions::InvalidOperationException.new("Can't compare version to #{other.class.name}!")) unless other.is_a?(KXI::Application::Version)
45
- return true if @major < other.major or @minor < other.minor or @patch < other.patch
46
- return true if @id != nil and other.identifier == nil
47
- return true if @id != nil and other.identifier != nil and @id < other.identifier
48
- return false
49
- end
50
-
51
- def <=(other)
52
- raise(KXI::Exceptions::InvalidOperationException.new("Can't compare version to #{other.class.name}!")) unless other.is_a?(KXI::Application::Version)
53
- return true if self == other
54
- return true if @major < other.major or @minor < other.minor or @patch < other.patch
55
- return true if @id != nil and other.identifier == nil
56
- return true if @id != nil and other.identifier != nil and @id < other.identifier
57
- return false
58
- end
59
-
60
- def >(other)
61
- return (not self <= other)
62
- end
63
-
64
- def >=(other)
65
- return (not self < other)
66
- end
67
-
68
- def self.parse(str)
69
- m = /^\s*(?'ma'\d+)\s*(\.\s*(?'mi'\d+))?\s*(\.\s*(?'pt'\d+))?\s*(-\s*(?'id'[0-9A-Z\-.]+))?\s*(\+\s*(?'mt'[0-9A-Z\-.]+))?\s*$/mi.match(str)
70
- raise(KXI::Exceptions::ParseException.new('version', str)) if m == nil
71
- return Version.new(m['ma'].to_i, m['mi'] != nil ? m['mi'].to_i : 0, m['pt'] != nil ? m['pt'].to_i : 0, m['id'], m['mt'])
72
- end
73
- end
74
- end
1
+ # Created by Matyáš Pokorný on 2018-01-27.
2
+
3
+ module KXI
4
+ module Application
5
+ # Represents a version of semantic versioning 2.0.0 (https://semver.org)
6
+ class Version
7
+ # Gets the major number of version
8
+ # @return [integer] Major number of version
9
+ def major
10
+ @major
11
+ end
12
+
13
+ # Gets the number minor of version
14
+ # @return [integer] Minor number of version
15
+ def minor
16
+ @minor
17
+ end
18
+
19
+ # Gets the number patch of version
20
+ # @return [integer] Patch number of version
21
+ def patch
22
+ @patch
23
+ end
24
+
25
+ # Gets the identifier of version
26
+ # @return [string] Identifier of version
27
+ def identifier
28
+ @id
29
+ end
30
+
31
+ # Gets the metadata of version
32
+ # @return [string] Metadata of version
33
+ def metadata
34
+ @meta
35
+ end
36
+
37
+ # Instantiates the {KXI::Application::Version} class
38
+ # @param [integer] major Major number of version
39
+ # @param [integer] minor Minor number of version
40
+ # @param [integer] patch Patch number of version
41
+ # @param [string,nil] id Identifier of version
42
+ # @param [string,nil] meta Metadata of version
43
+ def initialize(major, minor = 0, patch = 0, id = nil, meta = nil)
44
+ @major = major
45
+ @minor = minor
46
+ @patch = patch
47
+ @id = id
48
+ @meta = meta
49
+ end
50
+
51
+ # Converts class to string representation
52
+ # @return [string] String representation of class
53
+ def to_s
54
+ "#{@major}.#{@minor}.#{@patch}#{@id == nil ? '' : "-#{@id}"}#{@meta == nil ? '' : "+#{@meta}"}"
55
+ end
56
+
57
+ # Checks whether this version is equivalent to other version
58
+ # @return [bool] True when versions are equivalent; false otherwise
59
+ def ==(other)
60
+ return false unless other.is_a?(KXI::Application::Version)
61
+ return (@major == other.major and @minor == other.minor and @patch == other.patch and @id == other.identifier)
62
+ end
63
+
64
+ # Checks whether this version is lower than other version
65
+ # @return [bool] True when this version is lower than the other; false otherwise
66
+ def <(other)
67
+ raise(KXI::Exceptions::InvalidTypeException.new(other.class, KXI::Application::Version)) unless other.is_a?(KXI::Application::Version)
68
+ return true if @major < other.major or @minor < other.minor or @patch < other.patch
69
+ return true if @id != nil and other.identifier == nil
70
+ return true if @id != nil and other.identifier != nil and @id < other.identifier
71
+ return false
72
+ end
73
+
74
+ # Checks whether this version is lower than or equivalent to other version
75
+ # @return [bool] True when this version is lower than or equivalent to the other; false otherwise
76
+ def <=(other)
77
+ raise(KXI::Exceptions::InvalidTypeException.new(other.class, KXI::Application::Version)) unless other.is_a?(KXI::Application::Version)
78
+ return true if self == other
79
+ return true if @major < other.major or @minor < other.minor or @patch < other.patch
80
+ return true if @id != nil and other.identifier == nil
81
+ return true if @id != nil and other.identifier != nil and @id < other.identifier
82
+ return false
83
+ end
84
+
85
+ # Checks whether this version is grater than other version
86
+ # @return [bool] True when this version is grater than the other; false otherwise
87
+ def >(other)
88
+ return (not self <= other)
89
+ end
90
+
91
+ # Checks whether this version is grater than or equivalent to other version
92
+ # @return [bool] True when this version is grater than or equivalent to the other; false otherwise
93
+ def >=(other)
94
+ return (not self < other)
95
+ end
96
+
97
+ # Parses a version from its string representation
98
+ # @param [string] str String representation of the version
99
+ # @return [KXI::Application::Version] Version equivalent to given string
100
+ def self.parse(str)
101
+ m = /^\s*(?'ma'\d+)\s*(\.\s*(?'mi'\d+))?\s*(\.\s*(?'pt'\d+))?\s*(-\s*(?'id'[0-9A-Z\-.]+))?\s*(\+\s*(?'mt'[0-9A-Z\-.]+))?\s*$/mi.match(str)
102
+ raise(KXI::Exceptions::ParseException.new('version', str)) if m == nil
103
+ return Version.new(m['ma'].to_i, m['mi'] != nil ? m['mi'].to_i : 0, m['pt'] != nil ? m['pt'].to_i : 0, m['id'], m['mt'])
104
+ end
105
+ end
106
+ end
75
107
  end