Class: String

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.file_ext(file_name, opts = {}) ⇒ Object



43
44
45
# File 'lib/the_string_to_slug.rb', line 43

def file_ext file_name, opts = {}
  File.extname(file_name)[1..-1].to_s.to_slug_param opts
end

.file_name(name, opts = {}) ⇒ Object



47
48
49
50
51
# File 'lib/the_string_to_slug.rb', line 47

def file_name name, opts = {}
  name = File.basename name
  ext  = File.extname  name
  File.basename(name, ext).to_s.to_slug_param opts
end

.slugged_filename(name, opts = {}) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/the_string_to_slug.rb', line 53

def slugged_filename name, opts = {}
  name  = File.basename  name
  fname = self.file_name name, opts
  ext   = self.file_ext  name, opts

  return fname if ext.blank?
  [fname, ext].join('.')
end

.slugged_filepath(file_full_path, opts = {}) ⇒ Object



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

def slugged_filepath file_full_path, opts = {}
  fname = slugged_filename file_full_path, opts
  file_full_path.split('/')[0...-1].push(fname).join '/'
end

.to_slug_param(str, opts = {}) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/the_string_to_slug.rb', line 35

def to_slug_param str, opts = {}
  str = str.gsub(/\-{2,}/, '-').mb_chars
  sep = opts.delete(:sep) || '-'
  str = I18n::transliterate(str, opts)
  str = TheStringToSlug::basic_parametrize(str, sep)
  TheStringToSlug::parameterize(str, sep).to_s
end

Instance Method Details

#slugged_filename(opts = {}) ⇒ Object



23
24
25
# File 'lib/the_string_to_slug.rb', line 23

def slugged_filename opts = {}
  self.class.slugged_filename(self, opts)
end

#slugged_filepath(opts = {}) ⇒ Object



27
28
29
# File 'lib/the_string_to_slug.rb', line 27

def slugged_filepath opts = {}
  self.class.slugged_filepath(self, opts)
end

#to_slug_param(opts = {}) ⇒ Object



19
20
21
# File 'lib/the_string_to_slug.rb', line 19

def to_slug_param opts = {}
  self.class.to_slug_param(self, opts)
end