younker-string-extensions 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in younker-string-extensions.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,34 @@
1
+
2
+ # Monkey-patching String
3
+ class String
4
+ def make_url_friendly
5
+ # 1. Downcase string
6
+ # 2. Remove apostrophes so isn't changes to isnt
7
+ # 3. Replace any non-letter or non-number character with a space
8
+ # 4. Remove spaces from beginning and end of string
9
+ # 5. Replace groups of spaces with single hyphen
10
+ self.downcase.gsub(/'/, '').gsub(/[^A-Za-z0-9]+/, ' ').strip.gsub(/\ +/, '-')
11
+ end
12
+
13
+ # Stepping all over the native truncate()
14
+ def truncate(length = 100, truncate_string = "...")
15
+ # First regex truncates to the length, plus the rest of that word, if any.
16
+ # Second regex removes any trailing whitespace or punctuation (except ;).
17
+ # Unlike the regular truncate method, this avoids the problem with cutting
18
+ # in the middle of an entity ex.: truncate("this & that",9) => "this &am..."
19
+ # though it will not be the exact length.
20
+
21
+ return if self.blank?
22
+ l = length - truncate_string.length
23
+ self.length > length ? self[/\A.{#{l}}\w*\;?/m][/.*[\w\;]/m] + truncate_string : self
24
+ end
25
+
26
+ def strip_html
27
+ self.gsub(%r{</?[^>]+?>}, '')
28
+ end
29
+
30
+ def pluralize_if(boolean)
31
+ boolean ? self.pluralize : self
32
+ end
33
+ end
34
+
@@ -0,0 +1,7 @@
1
+ module Younker
2
+ module String
3
+ module Extensions
4
+ VERSION = "0.0.2"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "younker-string-extensions/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "younker-string-extensions"
7
+ s.version = Younker::String::Extensions::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Jason Younker"]
10
+ s.email = ["jason@ynkr.org"]
11
+ s.homepage = ""
12
+ s.summary = %q{Monkey patching string}
13
+ s.description = %q{Monkey patching string -- stuff that I find useful}
14
+
15
+ s.rubyforge_project = "younker-string-extensions"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: younker-string-extensions
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Jason Younker
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-03 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Monkey patching string -- stuff that I find useful
23
+ email:
24
+ - jason@ynkr.org
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Rakefile
35
+ - lib/younker-string-extensions.rb
36
+ - lib/younker-string-extensions/version.rb
37
+ - younker-string-extensions.gemspec
38
+ has_rdoc: true
39
+ homepage: ""
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project: younker-string-extensions
68
+ rubygems_version: 1.6.2
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Monkey patching string
72
+ test_files: []
73
+