Class: RuboCop::Cop::SketchUp::Namespace
- Inherits:
-
Object
- Object
- RuboCop::Cop::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.
13 14 15 |
# File 'lib/rubocop/sketchup/namespace.rb', line 13 def initialize(namespace) @namespace = namespace end |
Instance Attribute Details
#namespace ⇒ Object (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
#first ⇒ Object
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_root ⇒ Object
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 |
#parts ⇒ Object
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
40 41 42 |
# File 'lib/rubocop/sketchup/namespace.rb', line 40 def top_level? parts.last == 'Object' end |