Class: RuboCop::SketchUp::Namespace
- Defined in:
- lib/rubocop/sketchup/namespace.rb
Constant Summary collapse
- SEPARATOR =
'::'
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 17 18 |
# 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 |
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.
22 23 24 |
# File 'lib/rubocop/sketchup/namespace.rb', line 22 def first parts.find { |name| name != 'Object' } || 'Object' end |
#from_root ⇒ Object
Get a namespace string that is relative to Object.
27 28 29 30 31 |
# 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) ⇒ Object
33 34 35 |
# File 'lib/rubocop/sketchup/namespace.rb', line 33 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.
39 40 41 |
# File 'lib/rubocop/sketchup/namespace.rb', line 39 def parts namespace.split(SEPARATOR) end |
#top_level? ⇒ Boolean
43 44 45 |
# File 'lib/rubocop/sketchup/namespace.rb', line 43 def top_level? %w[Kernel Object].include?(parts.first) end |