Class: RuboCop::SketchUp::Namespace
- Defined in:
- lib/rubocop/sketchup/namespace.rb
Constant Summary collapse
- SEPARATOR =
'::'.freeze
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
-
#first ⇒ Object
Get the first component of a namespace relative to Object.
-
#from_root ⇒ Object
Get a namespace string that is relative to Object.
-
#initialize(namespace) ⇒ Namespace
constructor
A new instance of Namespace.
- #join(other) ⇒ Object
-
#parts ⇒ Object
Get the first component of a namespace relative to Object.
- #top_level? ⇒ Boolean
Constructor Details
#initialize(namespace) ⇒ Namespace
Returns a new instance of Namespace.
12 13 14 15 16 |
# File 'lib/rubocop/sketchup/namespace.rb', line 12 def initialize(namespace) raise TypeError unless namespace.is_a?(String) @namespace = namespace end |
Instance Attribute Details
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
7 8 9 |
# File 'lib/rubocop/sketchup/namespace.rb', line 7 def namespace @namespace end |
Instance Method Details
#first ⇒ Object
Get the first component of a namespace relative to Object. May return ‘Object’ if the namespace is in the global namespace.
20 21 22 |
# File 'lib/rubocop/sketchup/namespace.rb', line 20 def first parts.find { |name| name != 'Object' } || 'Object' end |
#from_root ⇒ Object
Get a namespace string that is relative to Object.
25 26 27 28 29 |
# File 'lib/rubocop/sketchup/namespace.rb', line 25 def from_root items = parts items.shift if items.size > 1 && items.first == 'Object' items.join(SEPARATOR) end |
#join(other) ⇒ Object
31 32 33 |
# File 'lib/rubocop/sketchup/namespace.rb', line 31 def join(other) self.class.new("#{@namespace}#{SEPARATOR}#{other}") end |
#parts ⇒ Object
Get the first component of a namespace relative to Object. May return ‘Object’ if the namespace is in the global namespace.
37 38 39 |
# File 'lib/rubocop/sketchup/namespace.rb', line 37 def parts namespace.split(SEPARATOR) end |
#top_level? ⇒ Boolean
41 42 43 |
# File 'lib/rubocop/sketchup/namespace.rb', line 41 def top_level? %w[Kernel Object].include?(parts.first) end |