string_helpers 0.0.2
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.
- data/.gitignore +2 -0
- data/README.md +45 -0
- data/Rakefile +9 -0
- data/lib/string_helpers.rb +7 -0
- data/lib/string_helpers/string.rb +23 -0
- data/lib/string_helpers/version.rb +3 -0
- data/test/test_string_helpers.rb +29 -0
- metadata +53 -0
data/.gitignore
ADDED
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# StringHelpers
|
2
|
+
StringHelpers extend some instance methods to String class
|
3
|
+
|
4
|
+
## Install
|
5
|
+
|
6
|
+
```sh
|
7
|
+
gem install string_helpers
|
8
|
+
```
|
9
|
+
or add to your Gemfile
|
10
|
+
|
11
|
+
```sh
|
12
|
+
gem string_helpers
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
Slug
|
17
|
+
```sh
|
18
|
+
"Jhon Doe".slug #=> "Jhon-Doe"
|
19
|
+
```
|
20
|
+
|
21
|
+
Fill
|
22
|
+
```sh
|
23
|
+
"Jhon Doe".slug
|
24
|
+
=> "Jhon Doe".fill 10 #=> "Jhon Doe "
|
25
|
+
|
26
|
+
"Jhon Doe".fill 5 #=> "Jhon..."
|
27
|
+
```
|
28
|
+
|
29
|
+
Apostrophe's
|
30
|
+
```sh
|
31
|
+
"Jhon Doe".apostrophe #=> "Jhon Doe’s"
|
32
|
+
|
33
|
+
"Marrys".apostrophe #=> "Marrys’"
|
34
|
+
```
|
35
|
+
|
36
|
+
Camelize
|
37
|
+
```sh
|
38
|
+
"jhon doe and marry".camelize! #=> "JhonDoeAndMarry"
|
39
|
+
```
|
40
|
+
|
41
|
+
## License
|
42
|
+
StringHelper is available under the MIT license.
|
43
|
+
|
44
|
+
|
45
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
include StringHelpers
|
3
|
+
|
4
|
+
String.class_eval do
|
5
|
+
def slug
|
6
|
+
self.gsub(" ", "-")
|
7
|
+
end
|
8
|
+
|
9
|
+
def fill characters
|
10
|
+
length = self.length
|
11
|
+
chars = characters - 1
|
12
|
+
return self[0..chars] << "..." if length > characters
|
13
|
+
self << "\s" * (characters - length) if length < characters
|
14
|
+
end
|
15
|
+
|
16
|
+
def apostrophe
|
17
|
+
self << (self[-1,1] == APOSTROPHE_VALIDATE ? APOSTROPHE_CHAR : (APOSTROPHE_CHAR + APOSTROPHE_VALIDATE))
|
18
|
+
end
|
19
|
+
|
20
|
+
def camelize!
|
21
|
+
self.split.each{|e| e.capitalize!}.join
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'string_helpers'
|
5
|
+
include StringHelpers
|
6
|
+
|
7
|
+
class StringHelpersTest < Test::Unit::TestCase
|
8
|
+
def test_string_slug
|
9
|
+
assert_equal "Jhon-Doe", "Jhon Doe".slug
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_string_fill
|
13
|
+
assert_equal "Jhon...", "Jhon Doe".fill(4)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_string_camelize
|
17
|
+
assert_equal "JhonDoe", "jhon doe".camelize!
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_string_apostrophe
|
21
|
+
word = "Marry#{APOSTROPHE_CHAR}#{APOSTROPHE_VALIDATE}"
|
22
|
+
assert_equal word, "Marry".apostrophe
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_string_apotrophe_with_s
|
26
|
+
word = "Marry#{APOSTROPHE_VALIDATE}#{APOSTROPHE_CHAR}"
|
27
|
+
assert_equal word, "Marry#{APOSTROPHE_VALIDATE}".apostrophe
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: string_helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Raphael Ivan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-18 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Extend some methods to String class.
|
15
|
+
email:
|
16
|
+
- raphaivan@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Rakefile
|
23
|
+
- README.md
|
24
|
+
- lib/string_helpers/version.rb
|
25
|
+
- lib/string_helpers/string.rb
|
26
|
+
- lib/string_helpers.rb
|
27
|
+
- test/test_string_helpers.rb
|
28
|
+
homepage: https://github.com/RaphaelIvan/string_helpers
|
29
|
+
licenses: []
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 1.8.24
|
49
|
+
signing_key:
|
50
|
+
specification_version: 3
|
51
|
+
summary: The libary extend some instance methods to String class.
|
52
|
+
test_files:
|
53
|
+
- test/test_string_helpers.rb
|