Sha256: 3a80fc67e24d6012b307f88b65b0a8289ccd5c2d2eb575bdb6d39c622c7bc0e7

Contents?: true

Size: 679 Bytes

Versions: 1

Compression:

Stored size: 679 Bytes

Contents

class SiteHub
  class Identifier
    attr_reader :id, :components

    def initialize(id)
      @components = id.to_s.split('|').collect(&:to_sym)
    end

    def child_label(label)
      components.empty? ? label : "#{self}|#{label}"
    end

    def root
      Identifier.new(components.first)
    end

    def sub_id
      Identifier.new(components[1..-1].join('|'))
    end

    def valid?
      !@components.empty?
    end

    def to_s
      components.join('|')
    end

    def to_sym
      to_s.to_sym
    end

    def ==(other)
      other.respond_to?(:to_sym) && to_sym == other.to_sym
    end

    def hash
      components.hash
    end

    alias eql? ==
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sitehub-0.5.0.alpha5 lib/sitehub/identifier.rb