slugity 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzdkYjE4NjdiYTA4ZTY0MDVhYjMwZDkzMWY5ZmNlNTE0NThjY2RiNA==
5
+ data.tar.gz: !binary |-
6
+ ZDZjZWE0YTY0M2M5Yjc4Y2JjNWY3YWVhYjI5MGUwYjljZTU5MTMyMg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NGY3Y2QyNzI0MjgyMjdkNGEzNTBkZDQzY2MzOTBkMTk1ZmZhNTFiMzI3MDkw
10
+ YmE2N2RkYWYzNTBmOWEzNWZiNGM5MTUzOWEwYjgzNjkxNDBkZjUyYmY4MjVi
11
+ YTQzNzVjNTQ1ZjBhYWI4OTRjZmM2YmYwMzlkNGRhMWU4MGE1Y2M=
12
+ data.tar.gz: !binary |-
13
+ NTFjOGIzNjNlZWQzYWJiMjQwNzk3NDBlMDQ5MDJiZGI4MTc0ZWIwMTJiMDZh
14
+ Y2M2YmEzYzRmMTAwMzFhNWU5NTk3M2VjZDU1M2IxNGZjNWIzM2VlODdlNGM2
15
+ YWNhYjM1ZDM1NjI2MmU1MzIzMzFkZmNhOWM2ZWRjMTE3NTk0ZTA=
@@ -0,0 +1,10 @@
1
+ require 'slugity'
2
+
3
+ class String
4
+ include Slugity
5
+
6
+ def to_slug
7
+ slugity self
8
+ end
9
+
10
+ end
@@ -0,0 +1,22 @@
1
+ module Slugity
2
+ module Util
3
+
4
+ class << self
5
+
6
+ # Trims begining and ending spaces from the string
7
+ #
8
+ # @param string [String]
9
+ # @return [String] the string without begining and ending spaces
10
+ def trim_string string
11
+
12
+ # capture spaces at the begining or end of the string
13
+ pattern = /(^\s+|\s+$)/
14
+
15
+ # strip characters that match the pattern
16
+ string.gsub( pattern, '' )
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Slugity
2
+ VERSION = '0.0.1'
3
+ end
data/lib/slugity.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'slugity/utilities'
2
+
3
+ module Slugity
4
+
5
+ # Converts the given string into a slug
6
+ #
7
+ # @param string [String] the string to slugity
8
+ # @return [String] the slug version of the provided string
9
+ def slugity string
10
+ string = Util.trim_string( string )
11
+
12
+ string.downcase.gsub(/\s|\//, '-').gsub(/\.|\'|\"|\<|\>|,|\(|\)|\:/,'').gsub(/\&/,'and').gsub(/\+/,'plus').gsub(/\=/,'equals')
13
+ end
14
+
15
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require File.expand_path("../../../lib/slugity/utilities", __FILE__)
3
+
4
+ describe Slugity::Util do
5
+
6
+ describe "#trim_string" do
7
+ it "removes begining and ending spaces" do
8
+ Slugity::Util.trim_string( " hello world" ).should == "hello world"
9
+ Slugity::Util.trim_string( "hello world " ).should == "hello world"
10
+ Slugity::Util.trim_string( " hello world " ).should == "hello world"
11
+ Slugity::Util.trim_string( " hello world " ).should == "hello world"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ require File.expand_path("../../lib/slugity", __FILE__)
3
+
4
+ test_strings = {
5
+ "Hello World" => "hello-world",
6
+ "one Flew_South" => "one-flew_south",
7
+ "Attr: Halp" => "attr-halp",
8
+ "Freddie & Bananas" => "freddie-and-bananas",
9
+ "One + Two = Three" => "one-plus-two-equals-three",
10
+ " hello world" => "hello-world",
11
+ "hello world " => "hello-world"
12
+ }
13
+
14
+ describe Slugity do
15
+
16
+ include Slugity
17
+
18
+ describe "#slugity()" do
19
+ it "returns a properly formatted string" do
20
+ test_strings.each do |input,output|
21
+ slugity( input ).should == output
22
+ end
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1 @@
1
+ require "rspec"
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ require File.expand_path("../../lib/slugity/extend_string", __FILE__)
3
+
4
+ describe String do
5
+
6
+ describe "#to_slug" do
7
+ it "should have been included on String" do
8
+ "hello world".to_slug.should == "hello-world"
9
+ end
10
+ end
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slugity
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Steven Sloan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ! ' Yet another slugging gem, this one makes sure you want to extend
14
+ the String class instead of assuming. '
15
+ email: stevenosloan@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/slugity/extend_string.rb
21
+ - lib/slugity/utilities.rb
22
+ - lib/slugity/version.rb
23
+ - lib/slugity.rb
24
+ - spec/slugity/trim_string_spec.rb
25
+ - spec/slugity_spec.rb
26
+ - spec/spec_helper.rb
27
+ - spec/string_spec.rb
28
+ homepage: http://github.com/stevenosloan/slugity
29
+ licenses: []
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 2.0.2
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Yet another slugging gem
51
+ test_files:
52
+ - spec/slugity/trim_string_spec.rb
53
+ - spec/slugity_spec.rb
54
+ - spec/spec_helper.rb
55
+ - spec/string_spec.rb