Module: Sashite::Qpi::Parser

Defined in:
lib/sashite/qpi/parser.rb

Overview

Parser for QPI (Qualified Piece Identifier) strings.

This parser splits the QPI string on the colon separator and delegates parsing of each component to the SIN and PIN libraries.

Examples:

Parser.parse("C:K")   # => { sin: <Sin::Identifier>, pin: <Pin::Identifier> }
Parser.parse("s:+r^") # => { sin: <Sin::Identifier>, pin: <Pin::Identifier> }

See Also:

Class Method Summary collapse

Class Method Details

.parse(input) ⇒ Hash

Parses a QPI string into its components.

Parameters:

  • input (String)

    The QPI string to parse

Returns:

  • (Hash)

    A hash with :sin and :pin keys containing Identifier instances

Raises:



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sashite/qpi/parser.rb', line 27

def self.parse(input)
  validate_input_type(input)
  validate_not_empty(input)

  sin_string, pin_string = split_components(input)

  sin = parse_sin(sin_string)
  pin = parse_pin(pin_string)

  { sin: sin, pin: pin }
end

.valid?(input) ⇒ Boolean

Validates a QPI string without raising an exception.

Parameters:

  • input (String)

    The QPI string to validate

Returns:

  • (Boolean)

    true if valid, false otherwise



43
44
45
46
47
48
49
50
# File 'lib/sashite/qpi/parser.rb', line 43

def self.valid?(input)
  return false unless ::String === input

  parse(input)
  true
rescue Errors::Argument
  false
end