Class: EncodedId::Rails::AnnotatedIdParser
- Inherits:
-
Object
- Object
- EncodedId::Rails::AnnotatedIdParser
- Defined in:
- lib/encoded_id/rails/annotated_id_parser.rb
Overview
Parses an annotated ID into its annotation and ID components.
Instance Attribute Summary collapse
-
#annotation ⇒ Object
readonly
: String?.
-
#id ⇒ Object
readonly
: String.
Instance Method Summary collapse
-
#initialize(annotated_id, separator: "_") ⇒ AnnotatedIdParser
constructor
A new instance of AnnotatedIdParser.
Constructor Details
#initialize(annotated_id, separator: "_") ⇒ AnnotatedIdParser
Returns a new instance of AnnotatedIdParser.
13 14 15 16 17 18 19 20 21 |
# File 'lib/encoded_id/rails/annotated_id_parser.rb', line 13 def initialize(annotated_id, separator: "_") if separator && annotated_id.include?(separator) parts = annotated_id.split(separator) @id = parts.last @annotation = parts[0..-2]&.join(separator) else @id = annotated_id end end |
Instance Attribute Details
#annotation ⇒ Object (readonly)
: String?
23 24 25 |
# File 'lib/encoded_id/rails/annotated_id_parser.rb', line 23 def annotation @annotation end |
#id ⇒ Object (readonly)
: String
24 25 26 |
# File 'lib/encoded_id/rails/annotated_id_parser.rb', line 24 def id @id end |