stringub-commons 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,17 +24,28 @@ Split strings into an array of words.
24
24
  "Serradura's house".words
25
25
  # >> ["Serradura's", "house"]
26
26
 
27
+ # If you question yourself:
28
+ # Whats the difference between the standard method String#split and words method?
29
+
30
+ "a, b, c, d-e,@ f'g.**".split
31
+ # >> ["a,", "b,", "c,", "d-e,@", "f'g.**"]
32
+
33
+ "a, b, c, d-e,@ f'g.**".words
34
+ # >> ["a", "b", "c", "d-e", "f'g"]
35
+
36
+ # The answer is:
37
+ # the words method just take words!
38
+
27
39
  ### Method: unique_spaces
28
40
  Removes a sequence of any kind of space characters per a unique whitespace.
29
-
30
- " \n abc ".unique_spaces
31
- # >> " abc "
41
+ " \n abc \n\n\r\t def \n\r ghi \n".unique_spaces
42
+ # >> " abc def ghi "
32
43
 
33
44
  #Tip:
34
45
  #If do you need remove trailing whitespaces. chain the String#strip method:
35
46
 
36
- " \n abc ".unique_spaces.strip
37
- # >> "abc"
47
+ " \n abc \n\n\r\t def \n\r ghi \n".unique_spaces.strip
48
+ # >> "abc def ghi"
38
49
 
39
50
  More examples can be founds in the tests.
40
51
 
@@ -1,51 +1,5 @@
1
- require "stringub-commons/version"
2
-
3
- # Stringub::Commons provides new methods for strings.
4
- module Stringub
5
- module Commons
6
- # Regexp pattern used to define words.
7
- WORD_PATTERN = /\w[\w\'\-]*/
8
- # Regexp pattern used to match any kind of space, ex: ' ', \n, \r, \t
9
- ANY_SPACE_PATTERN = /\s+/
10
-
11
- UNIQUE_SPACE = " "
12
-
13
- # Split strings into an array of words.
14
- # # Ex:
15
- # "Ruby on Rails".words
16
- # # >> ["Ruby", "on", "Rails"]
17
- #
18
- # "Serradura's house".words
19
- # # >> ["Serradura's", "house"]
20
- #
21
- # "Module and sub-module".words
22
- # # >> ["Module", "and", "aub-module"]
23
- def words
24
- self.scan(WORD_PATTERN)
25
- end
26
-
27
- # Removes a sequence of any kind of space characters per a unique whitespace.
28
- # # Ex:
29
- # " \n abc ".unique_spaces
30
- # # >> " abc "
31
- #
32
- # "\o/ \n\r\t ".unique_spaces
33
- # # >> "\o/ "
34
- # ===Tip:
35
- # If do you need remove trailing whitespaces. chain the String#strip method:
36
- # " \n abc ".unique_spaces.strip
37
- # # >> "abc"
38
- def unique_spaces
39
- self.gsub(ANY_SPACE_PATTERN, UNIQUE_SPACE)
40
- end
41
-
42
- # Removes a sequence of any kind of space characters per a unique whitespace.
43
- # Returns nil if str was not altered.
44
- def unique_spaces!
45
- self.gsub!(ANY_SPACE_PATTERN, UNIQUE_SPACE)
46
- end
47
- end
48
- end
1
+ require File.join("stringub-commons", "version")
2
+ require File.join("stringub-commons", "commons")
49
3
 
50
4
  class String
51
5
  include Stringub::Commons
@@ -0,0 +1,59 @@
1
+ # Stringub::Commons provides new methods for strings.
2
+ module Stringub
3
+ module Commons
4
+ # Regexp pattern used to define words.
5
+ WORD_PATTERN = /\w[\w\'\-]*/
6
+ # Regexp pattern used to match any kind of space, ex: ' ', \n, \r, \t
7
+ ANY_SPACE_PATTERN = /\s+/
8
+
9
+ UNIQUE_SPACE = " "
10
+
11
+ # Split strings into an array of words.
12
+ # # Ex:
13
+ # "Ruby on Rails".words
14
+ # # >> ["Ruby", "on", "Rails"]
15
+ #
16
+ # "Serradura's house".words
17
+ # # >> ["Serradura's", "house"]
18
+ #
19
+ # "Module and sub-module".words
20
+ # # >> ["Module", "and", "aub-module"]
21
+ #
22
+ # If you question yourself:
23
+ # Whats the difference between the standard method String#split and words method?
24
+ #
25
+ # "a, b, c, d-e,@ f'g.**".split
26
+ # >> ["a,", "b,", "c,", "d-e,@", "f'g.**"]
27
+ #
28
+ # "a, b, c, d-e,@ f'g.**".words
29
+ # >> ["a", "b", "c", "d-e", "f'g"]
30
+ #
31
+ # The answer is:
32
+ # the words method just take words!
33
+ def words
34
+ self.scan(WORD_PATTERN)
35
+ end
36
+
37
+ # Removes a sequence of any kind of space characters per a unique whitespace.
38
+ # # Ex:
39
+ # " \n abc \n\n\r\t def \n\r ghi \n".unique_spaces
40
+ # >> " abc def ghi "
41
+ #
42
+ # ===Tip:
43
+ # If do you need remove trailing whitespaces. chain the String#strip method:
44
+ #
45
+ # " \n abc \n\n\r\t def \n\r ghi \n".unique_spaces.strip
46
+ # >> "abc def ghi"
47
+ def unique_spaces
48
+ self.gsub(ANY_SPACE_PATTERN, UNIQUE_SPACE)
49
+ end
50
+
51
+ # Removes a sequence of any kind of space characters per a unique whitespace.
52
+ # Returns nil if str was not altered.
53
+ def unique_spaces!
54
+ self.gsub!(ANY_SPACE_PATTERN, UNIQUE_SPACE)
55
+ end
56
+ end
57
+ end
58
+
59
+
@@ -1,5 +1,5 @@
1
1
  module Stringub
2
2
  module Commons
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper')
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
3
  class Stringub::CommonsTest < Test::Unit::TestCase
4
4
 
@@ -1,3 +1,3 @@
1
1
  require 'rubygems' if RUBY_VERSION < "1.9"
2
- require 'test/unit'
2
+ require File.join('test', 'unit')
3
3
  require 'stringub-commons'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stringub-commons
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rodrigo Serradura
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-27 00:00:00 Z
18
+ date: 2011-07-27 00:00:00 -07:00
19
+ default_executable:
19
20
  dependencies: []
20
21
 
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."
@@ -33,10 +34,12 @@ files:
33
34
  - README.markdown
34
35
  - Rakefile
35
36
  - lib/stringub-commons.rb
37
+ - lib/stringub-commons/commons.rb
36
38
  - lib/stringub-commons/version.rb
37
39
  - stringub-commons.gemspec
38
- - test/stringub-commons_test.rb
40
+ - test/stringub-commons/commons_test.rb
39
41
  - test/test_helper.rb
42
+ has_rdoc: true
40
43
  homepage: ""
41
44
  licenses: []
42
45
 
@@ -66,9 +69,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
69
  requirements: []
67
70
 
68
71
  rubyforge_project: stringub-commons
69
- rubygems_version: 1.8.2
72
+ rubygems_version: 1.5.3
70
73
  signing_key:
71
74
  specification_version: 3
72
75
  summary: Useful methods for strings
73
- test_files: []
74
-
76
+ test_files:
77
+ - test/stringub-commons/commons_test.rb
78
+ - test/test_helper.rb