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.
- checksums.yaml +4 -4
- data/lib/kxi.rb +44 -39
- data/lib/kxi/application/config.rb +177 -177
- data/lib/kxi/application/config_reader.rb +16 -16
- data/lib/kxi/application/event.rb +35 -35
- data/lib/kxi/application/logger.rb +155 -155
- data/lib/kxi/application/version.rb +106 -74
- data/lib/kxi/application/version_expression.rb +94 -69
- data/lib/kxi/application/workspace.rb +105 -0
- data/lib/kxi/cli/anonymous_argument.rb +50 -50
- data/lib/kxi/cli/argument.rb +56 -56
- data/lib/kxi/cli/argument_values.rb +83 -83
- data/lib/kxi/cli/explicit_argument.rb +38 -38
- data/lib/kxi/cli/flag_argument.rb +15 -15
- data/lib/kxi/cli/named_argument.rb +59 -59
- data/lib/kxi/cli/property_list.rb +57 -48
- data/lib/kxi/cli/table.rb +82 -62
- data/lib/kxi/cli/verb.rb +282 -280
- data/lib/kxi/collections/array_collection.rb +106 -106
- data/lib/kxi/collections/enumerable.rb +527 -527
- data/lib/kxi/collections/enumerator.rb +31 -31
- data/lib/kxi/collections/hash_collection.rb +100 -100
- data/lib/kxi/collections/protected_collection.rb +20 -19
- data/lib/kxi/exceptions/abstract_exception.rb +34 -34
- data/lib/kxi/exceptions/argument_exception.rb +21 -21
- data/lib/kxi/exceptions/collection_exception.rb +13 -13
- data/lib/kxi/exceptions/configuration_exception.rb +36 -25
- data/lib/kxi/exceptions/dimension_mismatch_exception.rb +29 -0
- data/lib/kxi/exceptions/invalid_type_exception.rb +32 -32
- data/lib/kxi/exceptions/no_argument_exception.rb +20 -20
- data/lib/kxi/exceptions/not_implemented_exception.rb +12 -12
- data/lib/kxi/exceptions/out_of_range_exception.rb +43 -43
- data/lib/kxi/exceptions/parse_exception.rb +28 -20
- data/lib/kxi/exceptions/verb_expected_exception.rb +20 -20
- data/lib/kxi/exceptions/workspace_collision_exception.rb +21 -0
- data/lib/kxi/math/math.rb +45 -0
- data/lib/kxi/math/matrix.rb +303 -0
- data/lib/kxi/math/polynomial.rb +141 -101
- data/lib/kxi/math/vector.rb +181 -0
- data/lib/kxi/platform.rb +103 -57
- data/lib/kxi/reflection/stack_frame.rb +80 -80
- data/lib/kxi/version.rb +4 -4
- metadata +8 -3
- 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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
def
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
return (
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
return
|
72
|
-
end
|
73
|
-
|
74
|
-
|
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
|