Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/the_string_to_slug.rb
Class Method Summary collapse
- .file_ext(file_name, opts = {}) ⇒ Object
- .file_name(name, opts = {}) ⇒ Object
- .slugged_file(file_full_path, opts = {}) ⇒ Object
- .slugged_filename(name, opts = {}) ⇒ Object
- .to_slug_param(str, opts = {}) ⇒ Object
Instance Method Summary collapse
- #slugged_file(opts = {}) ⇒ Object
- #slugged_filename(opts = {}) ⇒ Object
- #to_slug_param(opts = {}) ⇒ Object
Class Method Details
.file_ext(file_name, opts = {}) ⇒ Object
33 34 35 |
# File 'lib/the_string_to_slug.rb', line 33 def file_ext file_name, opts = {} File.extname(file_name)[1..-1].to_s.to_slug_param opts end |
.file_name(name, opts = {}) ⇒ Object
37 38 39 40 41 |
# File 'lib/the_string_to_slug.rb', line 37 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_file(file_full_path, opts = {}) ⇒ Object
52 53 54 55 |
# File 'lib/the_string_to_slug.rb', line 52 def slugged_file file_full_path, opts = {} fname = slugged_filename file_full_path, opts file_full_path.split('/')[0...-1].push(fname).join '/' end |
.slugged_filename(name, opts = {}) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/the_string_to_slug.rb', line 43 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 |
.to_slug_param(str, opts = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/the_string_to_slug.rb', line 23 def to_slug_param str, opts = {} delimiter = opts.delete(:delimiter) || '-' str = str.gsub(/\-{2,}/, '-').mb_chars str = I18n::transliterate(str, opts) .gsub('_', delimiter) .gsub('-', delimiter) .parameterize(delimiter) .downcase.to_s end |
Instance Method Details
#slugged_file(opts = {}) ⇒ Object
15 16 17 |
# File 'lib/the_string_to_slug.rb', line 15 def slugged_file opts = {} self.class.slugged_file(self, opts) end |
#slugged_filename(opts = {}) ⇒ Object
11 12 13 |
# File 'lib/the_string_to_slug.rb', line 11 def slugged_filename opts = {} self.class.slugged_filename(self, opts) end |
#to_slug_param(opts = {}) ⇒ Object
7 8 9 |
# File 'lib/the_string_to_slug.rb', line 7 def to_slug_param opts = {} self.class.to_slug_param(self, opts) end |