Class: Pathname

Inherits:
Object
  • Object
show all
Defined in:
lib/adlint/prelude.rb

Instance Method Summary collapse

Instance Method Details

#add_ext(ext_str) ⇒ Object



143
144
145
# File 'lib/adlint/prelude.rb', line 143

def add_ext(ext_str)
  Pathname.new(self.to_s + ext_str)
end

#componentsObject



124
125
126
# File 'lib/adlint/prelude.rb', line 124

def components
  self.each_filename.to_a
end

#identical?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


147
148
149
150
151
152
153
154
155
156
# File 'lib/adlint/prelude.rb', line 147

def identical?(rhs)
  case rhs
  when Pathname
    self.cleanpath == rhs.cleanpath
  when String
    self.cleanpath == Pathname.new(rhs).cleanpath
  else
    false
  end
end

#real_componentsObject



129
130
131
# File 'lib/adlint/prelude.rb', line 129

def real_components
  self.realpath.each_filename.to_a
end

#strip(num = 0) ⇒ Object



137
138
139
140
141
# File 'lib/adlint/prelude.rb', line 137

def strip(num = 0)
  comps = self.components
  comps = comps.slice(num..-1) if num >= 0 && num < comps.size
  Pathname.new(comps.reduce { |stripped, comp| File.join(stripped, comp) })
end

#under?(parent_dpath) ⇒ Boolean

Returns:

  • (Boolean)


159
160
161
162
163
164
165
166
# File 'lib/adlint/prelude.rb', line 159

def under?(parent_dpath)
  lhs_comps, rhs_comps = self.real_components, parent_dpath.real_components
  if rhs_comps.size < lhs_comps.size
    rhs_comps.zip(lhs_comps).all? { |rhs, lhs| lhs == rhs }
  else
    false
  end
end