Class: EncodedId::Rails::AnnotatedIdParser

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#annotationObject (readonly)

: String?



23
24
25
# File 'lib/encoded_id/rails/annotated_id_parser.rb', line 23

def annotation
  @annotation
end

#idObject (readonly)

: String



24
25
26
# File 'lib/encoded_id/rails/annotated_id_parser.rb', line 24

def id
  @id
end