Class: Pathname

Inherits:
Object
  • Object
show all
Defined in:
lib/playlist_transfer/extensions.rb

Instance Method Summary collapse

Instance Method Details

#is_child?(root) ⇒ Boolean

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)

Returns:

  • (Boolean)


14
15
16
17
18
19
20
# 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_charsObject

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.



7
8
9
10
# 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