Class: Drum::RawRef
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
-
#is_token ⇒ Boolean
Whether the ref is a token (i.e. begins with @).
-
#raw ⇒ String
The raw text (@-stripped, though, if it's a token).
-
#text ⇒ Object
Returns the value of attribute text.
Class Method Summary collapse
-
.parse(raw) ⇒ RawRef
Parses a RawRef from the given string.
Instance Attribute Details
#is_token ⇒ Boolean
Returns 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 |
#raw ⇒ String
Returns 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 |
#text ⇒ Object
Returns the value of attribute 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.
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 |