Class: Epo::Ops::IpcClassUtil
- Inherits:
-
Object
- Object
- Epo::Ops::IpcClassUtil
- Defined in:
- lib/epo/ops/ipc_class_util.rb
Overview
Utility functions to work on Strings representing ipc classes.
Defined Under Namespace
Classes: InvalidIpcClassError, LevelNotSupportedError
Class Method Summary collapse
-
.children(ipc_class) ⇒ Array
List of all ipc classes one level more specific.
-
.main_classes ⇒ Array
[‘A’, ‘B’, …, ‘H’].
-
.parse_generic_format(generic) ⇒ String
There is a generic format for ipc classes that does not have the / as delimiter and leaves space for additions.
-
.valid_for_search?(ipc_class) ⇒ Boolean
check if the given ipc_class is valid as OPS search parameter.
Class Method Details
.children(ipc_class) ⇒ Array
Returns List of all ipc classes one level more specific.
47 48 49 50 51 52 53 54 |
# File 'lib/epo/ops/ipc_class_util.rb', line 47 def self.children(ipc_class) return main_classes if ipc_class.nil? valid = valid_for_search?(ipc_class) fail InvalidIpcClassError, ipc_class unless valid map = IpcClassHierarchy::Hierarchy fail LevelNotSupportedError, ipc_class unless map.key? ipc_class map[ipc_class] end |
.main_classes ⇒ Array
Returns [‘A’, ‘B’, …, ‘H’].
9 10 11 |
# File 'lib/epo/ops/ipc_class_util.rb', line 9 def self.main_classes %w( A B C D E F G H ) end |
.parse_generic_format(generic) ⇒ String
There is a generic format for ipc classes that does not have the / as delimiter and leaves space for additions. This parses it into the format the register search understands
27 28 29 30 31 32 33 34 |
# File 'lib/epo/ops/ipc_class_util.rb', line 27 def self.parse_generic_format(generic) ipc_class = generic if ipc_class.length > 4 match = ipc_class.match(/([A-Z]\d{2}[A-Z])(\d{4})(\d{6})$/) ipc_class = match[1] + (match[2].to_i).to_s + '/' + process_number(match[3]) end ipc_class end |
.valid_for_search?(ipc_class) ⇒ Boolean
check if the given ipc_class is valid as OPS search parameter
16 17 18 |
# File 'lib/epo/ops/ipc_class_util.rb', line 16 def self.valid_for_search?(ipc_class) ipc_class.match(/\A[A-H](\d{2}([A-Z](\d{1,2}\/\d{2,3})?)?)?\z/) end |