string-urlize 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,62 @@
1
+ require "string-urlize/version"
2
+
3
+ module StringUrlize
4
+
5
+ module InstanceMethods
6
+ def urlize options = {}
7
+ StringUrlize.urlize(self, options)
8
+ end
9
+ end
10
+
11
+ # ISO-8859-1 encoding
12
+ ACCENTS_MAPPING = {
13
+ 'E' => [200,201,202,203],
14
+ 'e' => [232,233,234,235],
15
+ 'A' => [192,193,194,195,196,197],
16
+ 'a' => [224,225,226,227,228,229,230],
17
+ 'C' => [199],
18
+ 'c' => [231],
19
+ 'O' => [210,211,212,213,214,216],
20
+ 'o' => [242,243,244,245,246,248],
21
+ 'I' => [204,205,206,207],
22
+ 'i' => [236,237,238,239],
23
+ 'U' => [217,218,219,220],
24
+ 'u' => [249,250,251,252],
25
+ 'N' => [209],
26
+ 'n' => [241],
27
+ 'Y' => [221],
28
+ 'y' => [253,255],
29
+ 'AE' => [306],
30
+ 'ae' => [346],
31
+ 'OE' => [188],
32
+ 'oe' => [189]
33
+ }.freeze
34
+
35
+ def self.transliterate_accents! string
36
+ each_accents_map { |letter, map| string.gsub! /[#{map}]/, letter }
37
+ end
38
+
39
+ def self.urlize dirty_string, options = {}
40
+ string = dirty_string.clone
41
+ transliterate_accents!(string) if options[:replace_accents]
42
+
43
+ string.gsub! /[^[:alnum:]\-\s\_]/, '' # Remove all characters except alphanumeric, spaces, dashes and underscores
44
+ string.gsub! /(\s|_)+/, '-' # Replace spaces and underscores by dashes
45
+
46
+ # Replace camelcase string to dash separated
47
+ string.gsub! /([A-Z]+)([A-Z][a-z])/, '\1-\2'
48
+ string.gsub! /([a-z\d])([A-Z])/, '\1-\2'
49
+
50
+ string.downcase!
51
+ string
52
+ end
53
+
54
+ private
55
+
56
+ def self.each_accents_map
57
+ ACCENTS_MAPPING.each { |letter, map| yield letter, map.pack('U*') }
58
+ end
59
+
60
+ end
61
+
62
+ String.send :include, StringUrlize::InstanceMethods
@@ -0,0 +1,3 @@
1
+ module StringUrlize
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: string-urlize
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ivan Garmatenko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-19 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cucumber
16
+ requirement: &74862740 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.9
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *74862740
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &74862350 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '2.9'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *74862350
36
+ description: ! 'Extends ruby "String" class with "urlize" method which converts string
37
+ to friendly url. It
38
+
39
+ removes all characters that couldn''t be used in url and replaces spaces/underscores
40
+ with dashes'
41
+ email:
42
+ - cheef.che@gmail.ru
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/string-urlize/version.rb
48
+ - lib/string-urlize.rb
49
+ homepage: http://github.com/cheef/urlize
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project: string-urlize
69
+ rubygems_version: 1.8.10
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Converts string to friendly url
73
+ test_files: []