Class: Pathname
- Inherits:
-
Object
- Object
- Pathname
- Defined in:
- lib/adlint/prelude.rb
Instance Method Summary collapse
- #add_ext(ext_str) ⇒ Object
- #components ⇒ Object
- #identical?(rhs) ⇒ Boolean
- #real_components ⇒ Object
- #strip(num = 0) ⇒ Object
- #under?(parent_dpath) ⇒ Boolean
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 |
#components ⇒ Object
124 125 126 |
# File 'lib/adlint/prelude.rb', line 124 def components self.each_filename.to_a end |
#identical?(rhs) ⇒ 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_components ⇒ Object
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
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 |