Sha256: 68949f8fba15fa054a724c031563b4b65493e4f9bbef5a2b85e61a30a42e6373

Contents?: true

Size: 600 Bytes

Versions: 1

Compression:

Stored size: 600 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
      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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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