Class: Drum::RawRef

Inherits:
Struct show all
Defined in:
lib/drum/model/raw_ref.rb

Overview

A 'half-parsed' reference to a resource, either a token or something else. The specifics are left to the service-specific Ref-parser.

Constant Summary collapse

TOKEN_PREFIX =
'@'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#is_tokenBoolean

Returns Whether the ref is a token (i.e. begins with @).

Returns:

  • (Boolean)

    Whether the ref is a token (i.e. begins with @)



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/drum/model/raw_ref.rb', line 10

RawRef = Struct.new(
  :text,
  :is_token,
  keyword_init: true
) do
  TOKEN_PREFIX = '@'

  # Parses a RawRef from the given string.
  #
  # @param [String] raw The raw string to be parsed
  # @return [RawRef] The parsed RawRef
  def self.parse(raw)
    if raw.start_with?(TOKEN_PREFIX)
      RawRef.new(text: raw.delete_prefix(TOKEN_PREFIX), is_token: true)
    else
      RawRef.new(text: raw, is_token: false)
    end
  end
end

#rawString

Returns The raw text (@-stripped, though, if it's a token).

Returns:

  • (String)

    The raw text (@-stripped, though, if it's a token)



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/drum/model/raw_ref.rb', line 10

RawRef = Struct.new(
  :text,
  :is_token,
  keyword_init: true
) do
  TOKEN_PREFIX = '@'

  # Parses a RawRef from the given string.
  #
  # @param [String] raw The raw string to be parsed
  # @return [RawRef] The parsed RawRef
  def self.parse(raw)
    if raw.start_with?(TOKEN_PREFIX)
      RawRef.new(text: raw.delete_prefix(TOKEN_PREFIX), is_token: true)
    else
      RawRef.new(text: raw, is_token: false)
    end
  end
end

#textObject

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



10
11
12
# File 'lib/drum/model/raw_ref.rb', line 10

def text
  @text
end

Class Method Details

.parse(raw) ⇒ RawRef

Parses a RawRef from the given string.

Parameters:

  • raw (String)

    The raw string to be parsed

Returns:

  • (RawRef)

    The parsed RawRef



21
22
23
24
25
26
27
# File 'lib/drum/model/raw_ref.rb', line 21

def self.parse(raw)
  if raw.start_with?(TOKEN_PREFIX)
    RawRef.new(text: raw.delete_prefix(TOKEN_PREFIX), is_token: true)
  else
    RawRef.new(text: raw, is_token: false)
  end
end