Class: CallSign::CallSign
- Inherits:
-
Object
- Object
- CallSign::CallSign
- Defined in:
- lib/call_sign/call_sign.rb
Constant Summary collapse
- EXTRACT_REGEX =
/^(?<prefix>[BFGIKMNRW]{1}|[A-Z][A-Z]|[A-Z]{1}[0-9]{1}|[0-9][A-Z]|[A-Z]|[0-9A-Z]{3})(?<separator>[0-9]{1})(?<suffix>[0-9A-Z]{1,5})$/
Instance Attribute Summary collapse
-
#call_sign ⇒ Object
readonly
Returns the value of attribute call_sign.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#prefix_string ⇒ Object
readonly
Returns the value of attribute prefix_string.
-
#separator_string ⇒ Object
readonly
Returns the value of attribute separator_string.
-
#suffix_string ⇒ Object
readonly
Returns the value of attribute suffix_string.
Class Method Summary collapse
Instance Method Summary collapse
- #country ⇒ Object
-
#initialize(call_sign) ⇒ CallSign
constructor
A new instance of CallSign.
- #valid? ⇒ Boolean
Constructor Details
#initialize(call_sign) ⇒ CallSign
Returns a new instance of CallSign.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/call_sign/call_sign.rb', line 8 def initialize(call_sign) components = CallSign.extract(call_sign) if components.is_a? Hash @call_sign = components[:text] @prefix = ITUPrefix.parse(components[:prefix]) @prefix_string = components[:prefix] @separator_string = components[:separator] @suffix_string = components[:suffix] @text = components[:text] @valid = true else @call_sign = nil @prefix_string = nil @separator_string = nil @suffix_string = nil @text = call_sign @valid = false end end |
Instance Attribute Details
#call_sign ⇒ Object (readonly)
Returns the value of attribute call_sign.
6 7 8 |
# File 'lib/call_sign/call_sign.rb', line 6 def call_sign @call_sign end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
6 7 8 |
# File 'lib/call_sign/call_sign.rb', line 6 def prefix @prefix end |
#prefix_string ⇒ Object (readonly)
Returns the value of attribute prefix_string.
6 7 8 |
# File 'lib/call_sign/call_sign.rb', line 6 def prefix_string @prefix_string end |
#separator_string ⇒ Object (readonly)
Returns the value of attribute separator_string.
6 7 8 |
# File 'lib/call_sign/call_sign.rb', line 6 def separator_string @separator_string end |
#suffix_string ⇒ Object (readonly)
Returns the value of attribute suffix_string.
6 7 8 |
# File 'lib/call_sign/call_sign.rb', line 6 def suffix_string @suffix_string end |
Class Method Details
.extract(call_sign) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/call_sign/call_sign.rb', line 37 def self.extract(call_sign) # Check for exceptions # 1-letter prefix # 2-letter prefix # 3-letter prefix # Match regex match = EXTRACT_REGEX.match(call_sign) return if !match { text: match.string, prefix: match[:prefix], separator: match[:separator], suffix: match[:suffix] } end |
Instance Method Details
#country ⇒ Object
29 30 31 |
# File 'lib/call_sign/call_sign.rb', line 29 def country valid? && prefix && prefix.country ? prefix.country : nil end |
#valid? ⇒ Boolean
33 34 35 |
# File 'lib/call_sign/call_sign.rb', line 33 def valid? @valid end |