radiospieler 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +26 -0
- data/Gemfile.lock +63 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/app.tmproj +93 -0
- data/config/app.yml +5 -0
- data/lib/core-extensions/array_ext.rb +5 -0
- data/lib/core-extensions/benchmark-logger.rb +31 -0
- data/lib/core-extensions/cgi_ext.rb +9 -0
- data/lib/core-extensions/hash_ext.rb +24 -0
- data/lib/core-extensions/object_ext.rb +8 -0
- data/lib/core-extensions/string_ext.rb +59 -0
- data/lib/core-extensions/string_without_accents.rb +92 -0
- data/lib/core-extensions/tls.rb +16 -0
- data/lib/core-extensions/uids.rb +16 -0
- data/lib/core-extensions/uri_ext.rb +10 -0
- data/lib/extensions/bitly.rb +34 -0
- data/lib/extensions/http.rb +60 -0
- data/lib/radiospieler.rb +13 -0
- data/lib/radiospieler/radiospieler.rb +13 -0
- data/lib/radiospieler/radiospieler/cache.rb +77 -0
- data/lib/radiospieler/radiospieler/config.rb +58 -0
- data/lib/radiospieler/radiospieler/logger.rb +26 -0
- data/lib/radiospieler/radiospieler/root.rb +36 -0
- data/script/watchr +28 -0
- data/test/app_test.rb +56 -0
- data/test/array_ext_test.rb +37 -0
- data/test/bitlify_test.rb +28 -0
- data/test/cache_test.rb +15 -0
- data/test/cgi_ext_test.rb +19 -0
- data/test/config.yml +8 -0
- data/test/config_test.rb +16 -0
- data/test/fixtures-vcr/bitly_limit_exceeded.yml +43 -0
- data/test/fixtures-vcr/bitly_ok.yml +46 -0
- data/test/fixtures-vcr/http_test.yml +389 -0
- data/test/hash_ext_test.rb +15 -0
- data/test/helper.rb +29 -0
- data/test/http_test.rb +18 -0
- data/test/string_ext_test.rb +26 -0
- data/test/tls_test.rb +35 -0
- data/test/uid_test.rb +17 -0
- metadata +226 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "pg"
|
7
|
+
gem "sqlite3"
|
8
|
+
gem "redis"
|
9
|
+
gem "micro_sql"
|
10
|
+
gem "htmlentities"
|
11
|
+
|
12
|
+
# Add dependencies to develop your gem here.
|
13
|
+
# Include everything needed to run rake, tests, features, etc.
|
14
|
+
group :development do
|
15
|
+
gem "bundler"
|
16
|
+
gem "jeweler"
|
17
|
+
|
18
|
+
# vcr stuff: this needs psych or else will crash
|
19
|
+
gem "vcr"
|
20
|
+
gem "webmock"
|
21
|
+
gem "psych"
|
22
|
+
|
23
|
+
gem 'simplecov', :require => false
|
24
|
+
gem "ruby-debug19"
|
25
|
+
end
|
26
|
+
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.2.7)
|
5
|
+
archive-tar-minitar (0.5.2)
|
6
|
+
columnize (0.3.6)
|
7
|
+
crack (0.3.1)
|
8
|
+
git (1.2.5)
|
9
|
+
htmlentities (4.3.1)
|
10
|
+
jeweler (1.8.3)
|
11
|
+
bundler (~> 1.0)
|
12
|
+
git (>= 1.2.5)
|
13
|
+
rake
|
14
|
+
rdoc
|
15
|
+
json (1.6.6)
|
16
|
+
linecache19 (0.5.12)
|
17
|
+
ruby_core_source (>= 0.1.4)
|
18
|
+
micro_sql (0.3.2)
|
19
|
+
pg
|
20
|
+
sqlite3
|
21
|
+
multi_json (1.2.0)
|
22
|
+
pg (0.13.2)
|
23
|
+
psych (1.3.1)
|
24
|
+
rake (0.9.2.2)
|
25
|
+
rdoc (3.12)
|
26
|
+
json (~> 1.4)
|
27
|
+
redis (2.2.2)
|
28
|
+
ruby-debug-base19 (0.11.25)
|
29
|
+
columnize (>= 0.3.1)
|
30
|
+
linecache19 (>= 0.5.11)
|
31
|
+
ruby_core_source (>= 0.1.4)
|
32
|
+
ruby-debug19 (0.11.6)
|
33
|
+
columnize (>= 0.3.1)
|
34
|
+
linecache19 (>= 0.5.11)
|
35
|
+
ruby-debug-base19 (>= 0.11.19)
|
36
|
+
ruby_core_source (0.1.5)
|
37
|
+
archive-tar-minitar (>= 0.5.2)
|
38
|
+
simplecov (0.6.1)
|
39
|
+
multi_json (~> 1.0)
|
40
|
+
simplecov-html (~> 0.5.3)
|
41
|
+
simplecov-html (0.5.3)
|
42
|
+
sqlite3 (1.3.5)
|
43
|
+
vcr (2.0.1)
|
44
|
+
webmock (1.8.6)
|
45
|
+
addressable (>= 2.2.7)
|
46
|
+
crack (>= 0.1.7)
|
47
|
+
|
48
|
+
PLATFORMS
|
49
|
+
ruby
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
bundler
|
53
|
+
htmlentities
|
54
|
+
jeweler
|
55
|
+
micro_sql
|
56
|
+
pg
|
57
|
+
psych
|
58
|
+
redis
|
59
|
+
ruby-debug19
|
60
|
+
simplecov
|
61
|
+
sqlite3
|
62
|
+
vcr
|
63
|
+
webmock
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 radiospiel
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= app
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to app
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 radiospiel. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "radiospieler"
|
18
|
+
gem.homepage = "http://github.com/radiospiel/radiospieler"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Application base code}
|
21
|
+
gem.description = %Q{Some basics that your application could benefit from.}
|
22
|
+
gem.email = "eno@open-lab.org"
|
23
|
+
gem.authors = ["radiospiel"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
task :default => :test
|
36
|
+
|
37
|
+
require 'rdoc/task'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "micro_sql #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.0
|
data/app.tmproj
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
+
<plist version="1.0">
|
4
|
+
<dict>
|
5
|
+
<key>currentDocument</key>
|
6
|
+
<string>lib/app/app/config.rb</string>
|
7
|
+
<key>documents</key>
|
8
|
+
<array>
|
9
|
+
<dict>
|
10
|
+
<key>expanded</key>
|
11
|
+
<true/>
|
12
|
+
<key>name</key>
|
13
|
+
<string>app</string>
|
14
|
+
<key>regexFolderFilter</key>
|
15
|
+
<string>!.*/(\.[^/]*|CVS|_darcs|coverage|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
|
16
|
+
<key>sourceDirectory</key>
|
17
|
+
<string></string>
|
18
|
+
</dict>
|
19
|
+
</array>
|
20
|
+
<key>fileHierarchyDrawerWidth</key>
|
21
|
+
<integer>221</integer>
|
22
|
+
<key>metaData</key>
|
23
|
+
<dict>
|
24
|
+
<key>Gemfile</key>
|
25
|
+
<dict>
|
26
|
+
<key>caret</key>
|
27
|
+
<dict>
|
28
|
+
<key>column</key>
|
29
|
+
<integer>17</integer>
|
30
|
+
<key>line</key>
|
31
|
+
<integer>8</integer>
|
32
|
+
</dict>
|
33
|
+
<key>firstVisibleColumn</key>
|
34
|
+
<integer>0</integer>
|
35
|
+
<key>firstVisibleLine</key>
|
36
|
+
<integer>0</integer>
|
37
|
+
</dict>
|
38
|
+
<key>lib/app/app/config.rb</key>
|
39
|
+
<dict>
|
40
|
+
<key>caret</key>
|
41
|
+
<dict>
|
42
|
+
<key>column</key>
|
43
|
+
<integer>21</integer>
|
44
|
+
<key>line</key>
|
45
|
+
<integer>27</integer>
|
46
|
+
</dict>
|
47
|
+
<key>firstVisibleColumn</key>
|
48
|
+
<integer>0</integer>
|
49
|
+
<key>firstVisibleLine</key>
|
50
|
+
<integer>0</integer>
|
51
|
+
</dict>
|
52
|
+
<key>lib/app/app/root.rb</key>
|
53
|
+
<dict>
|
54
|
+
<key>caret</key>
|
55
|
+
<dict>
|
56
|
+
<key>column</key>
|
57
|
+
<integer>0</integer>
|
58
|
+
<key>line</key>
|
59
|
+
<integer>6</integer>
|
60
|
+
</dict>
|
61
|
+
<key>firstVisibleColumn</key>
|
62
|
+
<integer>0</integer>
|
63
|
+
<key>firstVisibleLine</key>
|
64
|
+
<integer>0</integer>
|
65
|
+
</dict>
|
66
|
+
<key>lib/extensions/zz_geocoder.rb</key>
|
67
|
+
<dict>
|
68
|
+
<key>caret</key>
|
69
|
+
<dict>
|
70
|
+
<key>column</key>
|
71
|
+
<integer>21</integer>
|
72
|
+
<key>line</key>
|
73
|
+
<integer>8</integer>
|
74
|
+
</dict>
|
75
|
+
<key>firstVisibleColumn</key>
|
76
|
+
<integer>0</integer>
|
77
|
+
<key>firstVisibleLine</key>
|
78
|
+
<integer>0</integer>
|
79
|
+
</dict>
|
80
|
+
</dict>
|
81
|
+
<key>openDocuments</key>
|
82
|
+
<array>
|
83
|
+
<string>Gemfile</string>
|
84
|
+
<string>lib/app/app/config.rb</string>
|
85
|
+
<string>lib/app/app/root.rb</string>
|
86
|
+
<string>lib/extensions/zz_geocoder.rb</string>
|
87
|
+
</array>
|
88
|
+
<key>showFileHierarchyDrawer</key>
|
89
|
+
<true/>
|
90
|
+
<key>windowFrame</key>
|
91
|
+
<string>{{10, 0}, {1128, 746}}</string>
|
92
|
+
</dict>
|
93
|
+
</plist>
|
data/config/app.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "logger"
|
2
|
+
|
3
|
+
class Logger
|
4
|
+
class Benchmarker
|
5
|
+
attr :msg, true
|
6
|
+
attr :severity, true
|
7
|
+
|
8
|
+
def initialize(msg, severity = :warn)
|
9
|
+
@msg, @start = msg, Time.now
|
10
|
+
@severity = severity
|
11
|
+
end
|
12
|
+
|
13
|
+
def runtime
|
14
|
+
Time.now - @start
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
"#{msg}: #{(runtime * 1000).to_i} msecs"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def benchmark(msg = "Benchmark", opts = {}, &block)
|
23
|
+
benchmarker = Benchmarker.new(msg, opts[:severity] || :warn)
|
24
|
+
yield(benchmarker).tap do
|
25
|
+
self.send(benchmarker.severity, benchmarker.to_s) if benchmarker.runtime > (opts[:minimum] || -1)
|
26
|
+
end
|
27
|
+
rescue
|
28
|
+
warn "FAIL #{benchmarker}"
|
29
|
+
raise
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
def stringify_keys
|
5
|
+
r = []
|
6
|
+
each { |k,v| r << k.to_s << v }
|
7
|
+
Hash[*r]
|
8
|
+
end
|
9
|
+
|
10
|
+
def symbolize_keys
|
11
|
+
r = []
|
12
|
+
each { |k,v| r << (k.respond_to?(:to_sym) ? k.to_sym : k) << v }
|
13
|
+
Hash[*r]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Hash
|
18
|
+
extend Forwardable
|
19
|
+
delegate [:uid64, :crc32, :md5] => :calculate_stable_hashable
|
20
|
+
|
21
|
+
def calculate_stable_hashable
|
22
|
+
map { |k,v| "#{k.inspect}:#{v.inspect}" }.sort.join("//")
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "htmlentities"
|
2
|
+
|
3
|
+
# -- decode HTML entities -----------------------------------------------------
|
4
|
+
|
5
|
+
class String
|
6
|
+
module HtmlDecoder
|
7
|
+
def self.instance
|
8
|
+
@htmldecoder ||= HTMLEntities.new
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def unhtml
|
13
|
+
HtmlDecoder.instance.decode self
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# -- convert to UTF8 ----------------------------------------------------------
|
18
|
+
|
19
|
+
require 'iconv'
|
20
|
+
class String
|
21
|
+
def to_utf8
|
22
|
+
# require "charguess"
|
23
|
+
# encoding = CharGuess.guess(self)
|
24
|
+
# puts "encoding: #{encoding.inspect}"
|
25
|
+
# return self if !encoding || encoding == "UTF-8"
|
26
|
+
|
27
|
+
encoding = 'ISO-8859-1'
|
28
|
+
Iconv.conv('utf-8', encoding, self)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# -- remove accents -----------------------------------------------------------
|
33
|
+
|
34
|
+
require_relative "./string_without_accents"
|
35
|
+
|
36
|
+
class String
|
37
|
+
include WithoutAccents
|
38
|
+
end
|
39
|
+
|
40
|
+
class String
|
41
|
+
def sortkey
|
42
|
+
# Convert the key into an sortable ascii string
|
43
|
+
self.without_accents. # remove accents
|
44
|
+
downcase.
|
45
|
+
gsub(/^\s*(der|die|das|the|a|ein)\b\s*/, ""). # remove leading stop words
|
46
|
+
gsub(/[0-9]+/) { |s| "%03d" % s.to_i }. # fill in leading zeroes
|
47
|
+
gsub(/[^a-z0-9]/, "") # keep only letters and digits
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class String
|
52
|
+
def starts_with?(other)
|
53
|
+
length >= other.length && self[0, other.length] == other
|
54
|
+
end
|
55
|
+
|
56
|
+
def ends_with?(other)
|
57
|
+
length >= other.length && self[length - other.length .. -1] == other
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# RemoveAccents version 1.0.3 (c) 2008-2009 Solutions Informatiques Techniconseils inc.
|
2
|
+
#
|
3
|
+
# This module adds 2 methods to the string class.
|
4
|
+
# Up-to-date version and documentation available at:
|
5
|
+
#
|
6
|
+
# http://www.techniconseils.ca/en/scripts-remove-accents-ruby.php
|
7
|
+
#
|
8
|
+
# This script is available under the following license :
|
9
|
+
# Creative Commons Attribution-Share Alike 2.5.
|
10
|
+
#
|
11
|
+
# See full license and details at :
|
12
|
+
# http://creativecommons.org/licenses/by-sa/2.5/ca/
|
13
|
+
#
|
14
|
+
# Version history:
|
15
|
+
# * 1.0.3 : July 23 2009
|
16
|
+
# Corrected some incorrect character codes. Source is now wikipedia at:
|
17
|
+
# http://en.wikipedia.org/wiki/ISO/IEC_8859-1#Related_character_maps
|
18
|
+
# Thanks to Raimon Fernandez for pointing out the incorrect codes.
|
19
|
+
# * 1.0.2 : October 29 2008
|
20
|
+
# Slightly optimized version of urlize - Jonathan Grenier (jgrenier@techniconseils.ca)
|
21
|
+
# * 1.0.1 : October 29 2008
|
22
|
+
# First public revision - Jonathan Grenier (jgrenier@techniconseils.ca)
|
23
|
+
#
|
24
|
+
|
25
|
+
module WithoutAccents
|
26
|
+
|
27
|
+
# The extended characters map used by removeaccents. The accented characters
|
28
|
+
# are coded here using their numerical equivalent to sidestep encoding issues.
|
29
|
+
# These correspond to ISO-8859-1 encoding.
|
30
|
+
ACCENTS_MAPPING = {
|
31
|
+
'E' => [200,201,202,203],
|
32
|
+
'e' => [232,233,234,235],
|
33
|
+
'A' => [192,193,194,195,196,197],
|
34
|
+
'a' => [224,225,226,227,228,229,230],
|
35
|
+
'C' => [199],
|
36
|
+
'c' => [231],
|
37
|
+
'O' => [210,211,212,213,214,216],
|
38
|
+
'o' => [242,243,244,245,246,248],
|
39
|
+
'I' => [204,205,206,207],
|
40
|
+
'i' => [236,237,238,239],
|
41
|
+
'U' => [217,218,219,220],
|
42
|
+
'u' => [249,250,251,252],
|
43
|
+
'N' => [209],
|
44
|
+
'n' => [241],
|
45
|
+
'Y' => [221],
|
46
|
+
'y' => [253,255],
|
47
|
+
'AE' => [306],
|
48
|
+
'ae' => [346],
|
49
|
+
'OE' => [188],
|
50
|
+
'oe' => [189]
|
51
|
+
}
|
52
|
+
|
53
|
+
ACCENTS_MAPPING_REGEXPS = ACCENTS_MAPPING.map do |letter, accents|
|
54
|
+
packed = accents.pack('U*')
|
55
|
+
regexp = Regexp.new("[#{packed}]", nil) #, 'U')
|
56
|
+
|
57
|
+
[letter, regexp]
|
58
|
+
end
|
59
|
+
|
60
|
+
# Remove the accents from the string. Uses String::ACCENTS_MAPPING as the source map.
|
61
|
+
def without_accents
|
62
|
+
str = String.new(self)
|
63
|
+
ACCENTS_MAPPING_REGEXPS.each {|letter,regexp|
|
64
|
+
str.gsub!(regexp, letter)
|
65
|
+
}
|
66
|
+
str
|
67
|
+
end
|
68
|
+
|
69
|
+
=begin
|
70
|
+
|
71
|
+
# Convert a string to a format suitable for a URL without ever using escaped characters.
|
72
|
+
# It calls strip, removeaccents, downcase (optional) then removes the spaces (optional)
|
73
|
+
# and finally removes any characters matching the default regexp (/[^-_A-Za-z0-9]/).
|
74
|
+
#
|
75
|
+
# Options
|
76
|
+
#
|
77
|
+
# * :downcase => call downcase on the string (defaults to true)
|
78
|
+
# * :convert_spaces => Convert space to underscore (defaults to false)
|
79
|
+
# * :regexp => The regexp matching characters that will be converting to an empty string (defaults to /[^-_A-Za-z0-9]/)
|
80
|
+
def urlize(options = {})
|
81
|
+
options[:downcase] ||= true
|
82
|
+
options[:convert_spaces] ||= false
|
83
|
+
options[:regexp] ||= /[^-_A-Za-z0-9]/
|
84
|
+
|
85
|
+
str = self.strip.removeaccents
|
86
|
+
str.downcase! if options[:downcase]
|
87
|
+
str.gsub!(/\ /,'_') if options[:convert_spaces]
|
88
|
+
str.gsub(options[:regexp], '')
|
89
|
+
end
|
90
|
+
=end
|
91
|
+
|
92
|
+
end
|