Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/henshin/ext.rb

Instance Method Summary collapse

Instance Method Details

#directoryObject

Gets the directory from a string



68
69
70
71
# File 'lib/henshin/ext.rb', line 68

def directory
  self =~ /((\.?\/?[a-zA-Z0-9 _-]+\/)+)/
  $1
end

#extensionObject

Gets the extension from a string



62
63
64
65
# File 'lib/henshin/ext.rb', line 62

def extension
  parts = self.split('.')
  parts[parts.size-1]
end

#file_nameObject

Gets the filename from a string



74
75
76
# File 'lib/henshin/ext.rb', line 74

def file_name
  self.dup.gsub(/([a-zA-Z0-9_-]+\/)/, '')
end

#slugifyObject

Turns the string to a slug



51
52
53
54
55
56
57
58
59
# File 'lib/henshin/ext.rb', line 51

def slugify
  slug = self.clone
  slug.gsub!(/[']+/, '')
  slug.gsub!(/\W+/, ' ')
  slug.strip!
  slug.downcase!
  slug.gsub!(' ', '-')
  slug
end