class Yoda::Model::Path
Attributes
name[R]
Public Class Methods
build(path)
click to toggle source
@param path [Path, String] @return [Path]
# File lib/yoda/model/path.rb, line 8 def self.build(path) path.is_a?(Path) ? path : new(path) end
from_names(names)
click to toggle source
@param names [Array<Path, String>] @return [Path]
# File lib/yoda/model/path.rb, line 14 def self.from_names(names) new(names.join('::')) end
new(name)
click to toggle source
@param name [String]
# File lib/yoda/model/path.rb, line 19 def initialize(name) fail ArgumentError, name unless name.is_a?(String) @name = name end
Public Instance Methods
==(another)
click to toggle source
# File lib/yoda/model/path.rb, line 87 def ==(another) eql?(another) end
absolute?()
click to toggle source
# File lib/yoda/model/path.rb, line 24 def absolute? name.start_with?('::') end
basename()
click to toggle source
@return [String]
# File lib/yoda/model/path.rb, line 29 def basename @basename ||= begin if name.end_with?('::') '' else name.split('::').last || '' end end end
concat(another)
click to toggle source
@param another [Path, String] @return [Path]
# File lib/yoda/model/path.rb, line 61 def concat(another) if self.class.build(another).absolute? self else self.class.new([self.to_s, another.to_s].reject(&:empty?).join('::')) end end
eql?(another)
click to toggle source
# File lib/yoda/model/path.rb, line 91 def eql?(another) another.is_a?(Path) && name == another.name end
hash()
click to toggle source
# File lib/yoda/model/path.rb, line 83 def hash [self.class.name, name].hash end
namespaces()
click to toggle source
@return [Array<String>]
# File lib/yoda/model/path.rb, line 70 def namespaces name.split('::') end
parent_paths()
click to toggle source
@return [Array<Path>]
# File lib/yoda/model/path.rb, line 75 def parent_paths if spacename.empty? [] else [spacename] + Path.new(spacename).parent_paths end end
spacename()
click to toggle source
@return [String]
# File lib/yoda/model/path.rb, line 40 def spacename @spacename ||= begin if name.end_with?('::') name.gsub(/::\Z/, '') else name.split('::').slice(0..-2).join('::') end end end
split()
click to toggle source
# File lib/yoda/model/path.rb, line 55 def split name.gsub(/\A::/, '').split('::') + (name.end_with?('::') ? [''] : []) end
to_s()
click to toggle source
@return [String]
# File lib/yoda/model/path.rb, line 51 def to_s name end