Sha256: 859dbedd82f48b8fad70a8179899138f4603ae4582622e52043171ba9bfffe02

Contents?: true

Size: 679 Bytes

Versions: 6

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

    alias eql? ==

    def hash
      components.hash
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sitehub-0.5.0.alpha12 lib/sitehub/identifier.rb
sitehub-0.5.0.alpha11 lib/sitehub/identifier.rb
sitehub-0.5.0.alpha10 lib/sitehub/identifier.rb
sitehub-0.5.0.alpha8 lib/sitehub/identifier.rb
sitehub-0.5.0.alpha7 lib/sitehub/identifier.rb
sitehub-0.5.0.alpha6 lib/sitehub/identifier.rb