class RuboCop::SketchUp::Namespace

Constants

SEPARATOR

Attributes

namespace[R]

Public Class Methods

new(namespace) click to toggle source

@param [String] namespace

# File lib/rubocop/sketchup/namespace.rb, line 12
def initialize(namespace)
  unless namespace.is_a?(String)
    raise TypeError, "Expected String, got #{namespace.class.name}"
  end

  @namespace = namespace
end

Public Instance Methods

first() click to toggle source

Get the first component of a namespace relative to Object. May return 'Object' if the namespace is in the global namespace.

# File lib/rubocop/sketchup/namespace.rb, line 22
def first
  parts.find { |name| name != 'Object' } || 'Object'
end
from_root() click to toggle source

Get a namespace string that is relative to Object.

# File lib/rubocop/sketchup/namespace.rb, line 27
def from_root
  items = parts
  items.shift if items.size > 1 && items.first == 'Object'
  items.join(SEPARATOR)
end
join(other) click to toggle source
# File lib/rubocop/sketchup/namespace.rb, line 33
def join(other)
  self.class.new("#{@namespace}#{SEPARATOR}#{other}")
end
parts() click to toggle source

Get the first component of a namespace relative to Object. May return 'Object' if the namespace is in the global namespace.

# File lib/rubocop/sketchup/namespace.rb, line 39
def parts
  namespace.split(SEPARATOR)
end
top_level?() click to toggle source
# File lib/rubocop/sketchup/namespace.rb, line 43
def top_level?
  %w[Kernel Object].include?(parts.first)
end