Sha256: 685834b08920e919d893fa6a41d0b3fe15dcc286c57caefc933a0ebf46debc60

Contents?: true

Size: 446 Bytes

Versions: 3

Compression:

Stored size: 446 Bytes

Contents

# frozen_string_literal: true

module EncodedId
  module Rails
    class AnnotatedIdParser
      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

      attr_reader :annotation, :id
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
encoded_id-rails-1.0.0.beta3 lib/encoded_id/rails/annotated_id_parser.rb
encoded_id-rails-1.0.0.beta2 lib/encoded_id/rails/annotated_id_parser.rb
encoded_id-rails-1.0.0.beta1 lib/encoded_id/rails/annotated_id_parser.rb