Class: Epo::Ops::IpcClassUtil

Inherits:
Object
  • Object
show all
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

Class Method Details

.children(ipc_class) ⇒ Array

Returns List of all ipc classes one level more specific.

Parameters:

  • ipc_class (String)

    an ipc_class

Returns:

  • (Array)

    List of all ipc classes one level more specific.

Raises:

  • (InvalidIpcClassError)

    if parameter is not a valid ipc class in the format EPO understands

  • (LevelNotSupportedError)

    for parameters with ipc class depth >= 3 e.g. ‘A62B’ cannot be split further. It is currently not necessary to do so, it would only blow up the gem, and you do not want to query for all classes at the lowest level, as it takes too many requests.



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_classesArray

Returns [‘A’, ‘B’, …, ‘H’].

Returns:

  • (Array)

    [‘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

Examples:

parse_generic_format('A01B0003140000') #=> 'A01B3/14'

Parameters:

  • generic (String)

    ipc class in generic format

Returns:

  • (String)

    reformatted ipc class



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

Parameters:

  • ipc_class (String)

    an ipc class

Returns:

  • (Boolean)


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