stringub-commons 0.0.1
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 +5 -0
- data/Gemfile +10 -0
- data/README.markdown +18 -0
- data/Rakefile +55 -0
- data/lib/stringub-commons/version.rb +5 -0
- data/lib/stringub-commons.rb +26 -0
- data/stringub-commons.gemspec +20 -0
- data/test/stringub-commons_test.rb +50 -0
- data/test/test_helper.rb +3 -0
- metadata +77 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# serradura-stringub-commons
|
2
|
+
|
3
|
+
## Links
|
4
|
+
|
5
|
+
<a href='http://rubygems.org/gems/stringub_commons'>http://rubygems.org/gems/stringub_commons</a>
|
6
|
+
|
7
|
+
<a href="http://github.com/serradura/stringub_commons">http://github.com/serradura/stringub_commons</a>
|
8
|
+
|
9
|
+
## Description
|
10
|
+
This library borned from the early versions of string_utility_belt gem, this gem adds new common purpose methods to String class. E.g: split a string in words, replace a sequence of spaces per a unique space.
|
11
|
+
|
12
|
+
## Install
|
13
|
+
|
14
|
+
gem install stringub_commons
|
15
|
+
|
16
|
+
## Examples
|
17
|
+
Examples can be founds in the tests.
|
18
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems' if RUBY_VERSION < '1.9'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
require 'rcov/rcovtask'
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'rake/rdoctask'
|
10
|
+
rescue
|
11
|
+
require 'rdoc/task'
|
12
|
+
end
|
13
|
+
|
14
|
+
Rake::RDocTask.new do |rdoc|
|
15
|
+
files =['*.markdown', 'lib/**/*.rb']
|
16
|
+
rdoc.rdoc_files.add(files)
|
17
|
+
rdoc.main = "README.markdown" # page to start on
|
18
|
+
rdoc.title = "serradura/stringub_commons Docs"
|
19
|
+
rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
|
20
|
+
rdoc.options << '--line-numbers'
|
21
|
+
end
|
22
|
+
|
23
|
+
namespace :test do
|
24
|
+
Rake::TestTask.new do |t|
|
25
|
+
t.test_files = FileList['test/**/*.rb']
|
26
|
+
t.name = 'all'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def run_coverage(files)
|
31
|
+
rm_f "coverage"
|
32
|
+
rm_f "coverage.data"
|
33
|
+
|
34
|
+
# turn the files we want to run into a string
|
35
|
+
if files.length == 0
|
36
|
+
puts "No files were specified for testing"
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
files = files.join(" ")
|
41
|
+
|
42
|
+
exclude = '--exclude "usr/*"'
|
43
|
+
|
44
|
+
rcov = "rcov -Ilib:test --sort coverage --text-report #{exclude} --aggregate coverage.data"
|
45
|
+
cmd = "#{rcov} #{files}"
|
46
|
+
sh cmd
|
47
|
+
end
|
48
|
+
|
49
|
+
namespace :test do
|
50
|
+
desc 'Measures test coverage'
|
51
|
+
task :rcov do
|
52
|
+
run_coverage Dir["test/**/*.rb"]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "stringub-commons/version"
|
2
|
+
|
3
|
+
module Stringub
|
4
|
+
module Commons
|
5
|
+
WORD_PATTERN = /\w[\w\'\-]*/
|
6
|
+
ANY_SPACE_PATTERN = /\s+/
|
7
|
+
|
8
|
+
UNIQUE_SPACE = " "
|
9
|
+
|
10
|
+
def words
|
11
|
+
self.scan(WORD_PATTERN)
|
12
|
+
end
|
13
|
+
|
14
|
+
def unique_spaces
|
15
|
+
self.gsub(ANY_SPACE_PATTERN, UNIQUE_SPACE)
|
16
|
+
end
|
17
|
+
|
18
|
+
def unique_spaces!
|
19
|
+
self.gsub!(ANY_SPACE_PATTERN, UNIQUE_SPACE)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class String
|
25
|
+
include Stringub::Commons
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "stringub-commons/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "stringub-commons"
|
7
|
+
s.version = Stringub::Commons::VERSION
|
8
|
+
s.authors = ["Rodrigo Serradura"]
|
9
|
+
s.email = ["rserradura@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Useful methods for strings}
|
12
|
+
s.description = %q{This library borned from the early versions of string_utility_belt gem, this gem adds new common purpose methods to String class. E.g: split a string in words, replace a sequence of spaces per a unique space.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "stringub-commons"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class Stringub::CommonsTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@spaces_and_some_text = " \n \r \t\r\n foo \t bar "
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_return_a_single_word_in_array
|
10
|
+
assert_equal %w{Hello}, "Hello".words
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_return_all_words_as_element_in_array
|
14
|
+
assert_equal ["foo-foo", "bar's", "bar"], "foo-foo, bar's. bar!".words
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_replace_a_sequence_of_spaces_per_a_unique_space
|
18
|
+
string = @spaces_and_some_text.dup
|
19
|
+
assert_equal " foo bar ", string.unique_spaces
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_replace_the_left_spaces_by_only_one
|
23
|
+
assert_equal ' \o/!'.unique_spaces, ' \o/!'
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_should_replace_the_right_spaces_by_only_one
|
27
|
+
assert_equal '\o/! '.unique_spaces, '\o/! '
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_should_keep_the_original_content_after_calling_the_method
|
31
|
+
string = @spaces_and_some_text.dup
|
32
|
+
string.unique_spaces
|
33
|
+
assert_equal string, " \n \r \t\r\n foo \t bar "
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_should_return_the_same_content_if_any_space_replaced
|
37
|
+
assert_equal "Hello", "Hello".unique_spaces
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_should_not_generate_a_new_object
|
41
|
+
string = @spaces_and_some_text.dup
|
42
|
+
|
43
|
+
assert_same string, string.unique_spaces!
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_should_return_nil_if_nothing_changed
|
47
|
+
assert_nil "Hello".unique_spaces!
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stringub-commons
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Rodrigo Serradura
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-07-24 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: "This library borned from the early versions of string_utility_belt gem, this gem adds new common purpose methods to String class. E.g: split a string in words, replace a sequence of spaces per a unique space."
|
23
|
+
email:
|
24
|
+
- rserradura@gmail.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- README.markdown
|
35
|
+
- Rakefile
|
36
|
+
- lib/stringub-commons.rb
|
37
|
+
- lib/stringub-commons/version.rb
|
38
|
+
- stringub-commons.gemspec
|
39
|
+
- test/stringub-commons_test.rb
|
40
|
+
- test/test_helper.rb
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: ""
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project: stringub-commons
|
71
|
+
rubygems_version: 1.5.3
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Useful methods for strings
|
75
|
+
test_files:
|
76
|
+
- test/stringub-commons_test.rb
|
77
|
+
- test/test_helper.rb
|