Module: CLLI::Pattern::ClassMethods

Defined in:
lib/clli/pattern.rb

Overview

These methods will be available in the CLLI class.

Constant Summary collapse

DEFAULT_PATTERN_OPTIONS =
{
  strict: true,
  place_group: 'place',
  region_group: 'region',
  network_site_group: 'network_site',
  entity_code_group: 'entity_code',
  nonbuilding_code_group: 'location_code',
  nonbuilding_id_group: 'location_id',
  customer_code_group: 'customer_code',
  customer_id_group: 'customer_id'
}

Instance Method Summary collapse

Instance Method Details

#aObject

A character group containing all alpha characters.



160
161
162
# File 'lib/clli/pattern.rb', line 160

def a
  'A-Z'
end

#a1Object

A character group excluding B, D, I, O, T, U, W, and Y.



148
149
150
# File 'lib/clli/pattern.rb', line 148

def a1
  'ACE-HJ-NP-SVXZ'
end

#a2Object

A character group excluding G.



154
155
156
# File 'lib/clli/pattern.rb', line 154

def a2
  'A-FH-Z'
end

#customer_location_pattern(**options) ⇒ Object

Get the customer non-building location pattern.

Params:

options

see #pattern for more details.



140
141
142
143
144
# File 'lib/clli/pattern.rb', line 140

def customer_location_pattern(**options)
  options = DEFAULT_PATTERN_OPTIONS.merge(options)
  pattern = named_group(options[:customer_code_group], "[#{n}]")
  pattern << named_group(options[:customer_id_group], "[#{a}][#{n}]{3}")
end

#entity_code_pattern(**options) ⇒ Object

Get the entity code pattern.

Params:

options

see #pattern for more details.



86
87
88
89
90
91
92
93
94
# File 'lib/clli/pattern.rb', line 86

def entity_code_pattern(**options)
  options = DEFAULT_PATTERN_OPTIONS.merge(options)
  named_group(options[:entity_code_group], [
    switching_entity_code_pattern, # (Table B)
    switchboard_and_desk_entity_code_pattern, # (Table C)
    miscellaneous_switching_termination_entity_code_pattern, # (Table D)
    nonswitching_entity_code_pattern # (Table E)
  ].join('|'))
end

#miscellaneous_switching_termination_entity_code_patternObject

Miscellaneous switching termination entities (Table D)



115
116
117
# File 'lib/clli/pattern.rb', line 115

def miscellaneous_switching_termination_entity_code_pattern
  ["[#{n}][AXCTWDEINPQ]D", "[#{x}][UM]D"].join('|')
end

#nObject

A character group containing all digit characters.



166
167
168
# File 'lib/clli/pattern.rb', line 166

def n
  '0-9'
end

#network_site_pattern(**options) ⇒ Object

Get the network site code pattern.

Params:

options

see #pattern for more details.



76
77
78
79
# File 'lib/clli/pattern.rb', line 76

def network_site_pattern(**options)
  options = DEFAULT_PATTERN_OPTIONS.merge(options)
  named_group(options[:network_site_group], options[:strict] ? "(?:[#{a}]{2}|[#{n}]{2})" : "(?:[#{a}#{n}]{2})")
end

#nonbuilding_location_pattern(**options) ⇒ Object

Get the non-building location code pattern.

Params:

options

see #pattern for more details.



129
130
131
132
133
# File 'lib/clli/pattern.rb', line 129

def nonbuilding_location_pattern(**options)
  options = DEFAULT_PATTERN_OPTIONS.merge(options)
  pattern = named_group(options[:nonbuilding_code_group], "[#{a}]")
  pattern << named_group(options[:nonbuilding_id_group], "[#{n}]{4}")
end

#nonswitching_entity_code_patternObject

Non-Switching Entities (Table E)



120
121
122
# File 'lib/clli/pattern.rb', line 120

def nonswitching_entity_code_pattern
  ["[FAEKMPSTW][#{x2}][#{x1}]", "Q[#{n}][#{n}]"].join('|')
end

#pattern(**options) ⇒ Object

Get the complete CLLI pattern.

Params:

options

the following options are supported.

:strict

whether or not the rules in section 795-100-100 are enforced for all fields.

:place_group

the name to use for the place abbreviation.

:region_group

the name to use for the region code.

:network_site_group

the name to use for the network site code.

:entity_code_group

the name to use for the entity code.

:nonbuilding_code_group

the name to use for the nonbuilding code.

:nonbuilding_id_group

the name to use for the nonbuilding ID.

:customer_code_group

the name to use for the customer code.

:customer_id_group

the name to use for the customer ID.



42
43
44
45
46
47
48
49
# File 'lib/clli/pattern.rb', line 42

def pattern(**options)
  place = place_pattern(options)
  network_site = network_site_pattern(options)
  entity_code = entity_code_pattern(options)
  nonbuilding_location = nonbuilding_location_pattern(options)
  customer_location = customer_location_pattern(options)
  "#{place}(?:#{network_site}(?:#{entity_code})?|#{nonbuilding_location}|#{customer_location})"
end

#place_pattern(**options) ⇒ Object

Get the place abbreviation and region code pattern.

Params:

options

see #pattern for more details.



65
66
67
68
69
# File 'lib/clli/pattern.rb', line 65

def place_pattern(**options)
  options = DEFAULT_PATTERN_OPTIONS.merge(options)
  pattern = named_group(options[:place_group], options[:strict] ? "[#{a}]{4}|[#{a}]{3}[ ]|[#{a}]{2}[ ]{2}" : "[#{x}\s]{4}")
  pattern << named_group(options[:region_group], '[A-Z]{2}')
end

#regexp(**options) ⇒ Object

Get the complete CLLI pattern as a compiled Regexp.

Params:

options

see #pattern for more details.



56
57
58
# File 'lib/clli/pattern.rb', line 56

def regexp(**options)
  Regexp.new(pattern(options))
end

#switchboard_and_desk_entity_code_patternObject

Switchboard and Desk Termination Entities (Table C)



110
111
112
# File 'lib/clli/pattern.rb', line 110

def switchboard_and_desk_entity_code_pattern
  "[#{n}][CDBINQWMVROLPEUTZ#{n}]B"
end

#switching_entity_code_patternObject

Switching Entities (Table B)



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/clli/pattern.rb', line 97

def switching_entity_code_pattern
  [
    "(?:MG|SG|CG|DS|[#{n}][#{n}])[#{x1}]",
    "[CB#{n}][#{n}]T",
    "[#{n}]GT",
    "Z[#{a}]Z",
    "RS[#{n}]",
    "X[#{a}]X",
    "CT[#{x1}]"
  ].join('|')
end

#xObject

A character group containing all alpha and digit characters.



172
173
174
# File 'lib/clli/pattern.rb', line 172

def x
  a + n
end

#x1Object

A character group containing both a1 and all digit characters.



178
179
180
# File 'lib/clli/pattern.rb', line 178

def x1
  a1 + n
end

#x2Object

A character group containing both a2 and all digit characters.



184
185
186
# File 'lib/clli/pattern.rb', line 184

def x2
  a2 + n
end