class Pathname
Public Instance Methods
is_child?(root)
click to toggle source
Adds new method to Pathname
, which can check if path itself is child of root (parameter, root is another Pathname
) It is used in MusicTrack
class to determine if track initialization is correct (if file is really located in defined directory)
# File lib/playlist_transfer/extensions.rb, line 14 def is_child?(root) if self.to_s.size >= root.to_s.size return self.to_s[0...root.to_s.size] == root.to_s && (self.to_s.size == root.to_s.size || self.to_s[root.to_s.size] == ?/ ) else return false end end
no_special_chars()
click to toggle source
Adds new method to Pathname
, which removes accented characters from Pathname
. Then removes spaces and any special characters (they are replaced by _). This method returns another Pathname
.
# File lib/playlist_transfer/extensions.rb, line 7 def no_special_chars transliterated=ActiveSupport::Inflector.transliterate(self.to_s) return Pathname.new(transliterated.gsub!(/[^0-9A-Za-z\/.]/, '_')) end