Class: RuboCop::Cop::SketchUp::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/sketchup/namespace.rb

Constant Summary collapse

SEPARATOR =
'::'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace) ⇒ Namespace

Returns a new instance of Namespace.

Parameters:

  • namespace (String)


13
14
15
# File 'lib/rubocop/sketchup/namespace.rb', line 13

def initialize(namespace)
  @namespace = namespace
end

Instance Attribute Details

#namespaceObject (readonly)

Returns the value of attribute namespace.



8
9
10
# File 'lib/rubocop/sketchup/namespace.rb', line 8

def namespace
  @namespace
end

Instance Method Details

#firstObject

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



19
20
21
# File 'lib/rubocop/sketchup/namespace.rb', line 19

def first
  parts.find { |name| name != 'Object' } || 'Object'
end

#from_rootObject

Get a namespace string that is relative to Object.



24
25
26
27
28
# File 'lib/rubocop/sketchup/namespace.rb', line 24

def from_root
  items = parts
  items.shift if items.size > 1 && items.first == 'Object'
  items.join(SEPARATOR)
end

#join(other) ⇒ Object



30
31
32
# File 'lib/rubocop/sketchup/namespace.rb', line 30

def join(other)
  self.class.new("#{@namespace}#{SEPARATOR}#{other}")
end

#partsObject

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



36
37
38
# File 'lib/rubocop/sketchup/namespace.rb', line 36

def parts
  namespace.split(SEPARATOR)
end

#top_level?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/rubocop/sketchup/namespace.rb', line 40

def top_level?
  parts.last == 'Object'
end