string_utility_belt 0.2.5 → 0.3.0
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 +6 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +28 -0
- data/README.markdown +145 -0
- data/Rakefile +41 -33
- data/lib/string_utility_belt/entities.rb +23 -0
- data/lib/string_utility_belt/general.rb +72 -0
- data/lib/{match_rank → string_utility_belt}/match_rank.rb +30 -24
- data/lib/string_utility_belt/regex_me_helper.rb +100 -0
- data/lib/string_utility_belt/regex_me_to_search.rb +107 -0
- data/lib/string_utility_belt/tags.rb +22 -0
- data/lib/string_utility_belt/version.rb +1 -6
- data/lib/string_utility_belt.rb +6 -17
- data/test/string_utility_belt/entities_test.rb +17 -0
- data/test/string_utility_belt/general_test.rb +73 -0
- data/test/string_utility_belt/match_rank_test.rb +64 -0
- data/test/string_utility_belt/regex_me_helper_test.rb +117 -0
- data/test/string_utility_belt/regex_me_to_search_test.rb +106 -0
- data/test/string_utility_belt/tags_test.rb +25 -0
- data/test/test_helper.rb +5 -0
- metadata +30 -22
- data/lib/general/general.rb +0 -36
- data/lib/html_and_aml/helpers/entities.rb +0 -16
- data/lib/html_and_aml/helpers/tags.rb +0 -13
- data/lib/html_and_aml/html_and_aml.rb +0 -10
- data/lib/regex_me/helpers/string/regex_me.rb +0 -73
- data/lib/regex_me/regex_me.rb +0 -84
- data/string_utility_belt.gemspec +0 -10
data/lib/string_utility_belt.rb
CHANGED
@@ -1,18 +1,7 @@
|
|
1
|
+
require 'string_utility_belt/version'
|
1
2
|
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
|
7
|
-
module StringUtilityBelt
|
8
|
-
|
9
|
-
include RegexMe::To::Search
|
10
|
-
include MatchRank
|
11
|
-
include General
|
12
|
-
include HtmlAndAML
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
class String
|
17
|
-
include StringUtilityBelt
|
18
|
-
end
|
3
|
+
require 'string_utility_belt/regex_me_to_search'
|
4
|
+
require 'string_utility_belt/general'
|
5
|
+
require 'string_utility_belt/match_rank'
|
6
|
+
require 'string_utility_belt/tags'
|
7
|
+
require 'string_utility_belt/entities'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class EntitiesTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_should_decode_entities
|
6
|
+
assert_equal "<TAG>", "<TAG>".decode_entities
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_decode_entities_and_clean_up_the_tags
|
10
|
+
assert_equal "", "<TAG>".decode_entities_and_cleaner
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_should_encode_anything_that_can_be_transformed_into_an_entity
|
14
|
+
assert_equal "<TAG>", "<TAG>".generate_entities
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class GeneralTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@spaces_and_some_text = " \n \r \t\r\n foo \t bar "
|
7
|
+
|
8
|
+
@text = %q{Texto de teste!
|
9
|
+
Esta classe deverá fazer a busca por uma ou um grupo de palavras
|
10
|
+
em um texto e retornar um rank com a quantidade identificada.}
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_return_a_single_word_in_array
|
14
|
+
assert_equal %w{Hello}, "Hello".words
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_return_all_words_as_element_in_array
|
18
|
+
assert_equal ["foo-foo", "bar's", "bar"], "foo-foo, bar's. bar!".words
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_should_replace_a_sequence_of_space_per_a_unique_space
|
22
|
+
assert_equal " foo bar ", @spaces_and_some_text.simple_space
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_should_replace_the_left_spaces_by_only_one
|
26
|
+
assert_equal ' \o/!'.simple_space, ' \o/!'
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_should_replace_the_right_spaces_by_only_one
|
30
|
+
assert_equal '\o/! '.simple_space, '\o/! '
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_should_be_the_same_result_after_calling_the_method
|
34
|
+
string = @spaces_and_some_text.dup
|
35
|
+
assert_equal string, " \n \r \t\r\n foo \t bar "
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_should_return_the_same_text_if_nothing_changed
|
39
|
+
assert_equal "Hello", "Hello".simple_space
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
#describe #simple_space!
|
44
|
+
def test_should_not_generate_a_new_object
|
45
|
+
@spaces_and_some_text.simple_space!
|
46
|
+
|
47
|
+
assert_not_same ' foo bar ', @spaces_and_some_text
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_should_return_nil_if_nothing_changed
|
51
|
+
assert_nil "Hello".simple_space!
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
# describe #have_this_words?
|
56
|
+
def test_should_be_true_if_find_all_of_the_text_fragments
|
57
|
+
assert @text.have_this_words?("busca ran".words)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_should_be_false_because_not_exists_the_ran_word
|
61
|
+
assert_not_equal true, @text.have_this_words?("ran busca".words, true)
|
62
|
+
end
|
63
|
+
|
64
|
+
# describe #not_have_this_words?
|
65
|
+
def test_should_be_true_if_not_find_all_of_the_searched_words
|
66
|
+
assert_equal true, @text.not_have_this_words?("ran busc".words, true)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_should_match_even_if_there_are_characters_variations
|
70
|
+
text = "São páúlõ is a very nice city!"
|
71
|
+
assert text.have_this_words?("sao paulo".words, :latin_chars_variations => true)
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class MatchRankTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@sequence = "a aa aaa aaaa aaaaa b bb bbb bbbb"
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_return_a_hash_with_the_results_of_exact_and_inexact_matches
|
10
|
+
analysis = "".total_frequency_by('test')
|
11
|
+
expected = {:exact => 0, :matched => 0}
|
12
|
+
assert_equal(expected, analysis)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_return_how_many_times_a_text_pattern_was_matched
|
16
|
+
analysis = @sequence.total_frequency_by('bb')
|
17
|
+
matched = analysis[:matched]
|
18
|
+
assert_equal 3, matched
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_should_return_how_many_exact_matches
|
22
|
+
analysis = @sequence.total_frequency_by('bb')
|
23
|
+
exact_matches = analysis[:exact]
|
24
|
+
assert_equal(1, exact_matches)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_return_an_analysis_of_all_received_words
|
28
|
+
analysis = @sequence.total_frequency_by('aa bb'.words)
|
29
|
+
expected = {:matched=> 7, :exact=> 2}
|
30
|
+
assert_equal(expected, analysis)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_should_return_the_analysis_of_total_frequency_by_method_and_precision
|
34
|
+
analysis = @sequence.match_and_score_by('aa bb'.words)
|
35
|
+
expected = {:exact=>2.0, :matched=>7.0, :precision=>28.5714285714286}
|
36
|
+
assert_in_delta(expected[:precision], analysis[:precision], 0.00001)
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def test_should_return_a_hash_with_the_results_for_exact_and_inexact_per_word_criteria
|
41
|
+
analysis = "".words_frequency_by('test')
|
42
|
+
expected = {:exact => {}, :matched => {}}
|
43
|
+
assert_equal(expected, analysis)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_should_return_how_many_times_a_text_pattern_was_matched_per_word_criteria
|
47
|
+
analysis = @sequence.words_frequency_by('aa')
|
48
|
+
matched = analysis[:matched]
|
49
|
+
assert_equal({'aa' => 4}, matched)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_should_return_how_many_exact_matches_per_word_criteria
|
53
|
+
analysis = @sequence.words_frequency_by('aa')
|
54
|
+
exact_matches = analysis[:exact]
|
55
|
+
assert_equal({'aa' => 1}, exact_matches)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_should_return_an_analysis_of_all_received_words_per_words_criteria
|
59
|
+
analysis = @sequence.words_frequency_by('aa bb'.words)
|
60
|
+
expected = {:matched=>{"bb"=>3, "aa"=>4}, :exact=>{"bb"=>1, "aa"=>1}}
|
61
|
+
assert_equal(expected, analysis)
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
4
|
+
|
5
|
+
class RegexMeHelperTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_should_create_a_string_with_the_latin_char_variations_for_the_letter_A
|
8
|
+
assert_equal("(a|à|á|â|ã|ä)", "a".regex_latin_ci_list)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_should_create_a_string_with_the_latin_char_variations_for_the_letter_E
|
12
|
+
assert_equal("(e|è|é|ê|ë)", "e".regex_latin_ci_list)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_create_a_string_with_the_latin_char_variations_for_the_letter_I
|
16
|
+
assert_equal("(i|ì|í|î|ï)", "i".regex_latin_ci_list)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_should_create_a_string_with_the_latin_char_variations_for_the_letter_O
|
20
|
+
assert_equal("(o|ò|ó|ô|õ|ö)", "o".regex_latin_ci_list)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_should_create_a_string_with_the_latin_char_variations_for_the_letter_U
|
24
|
+
assert_equal("(u|ù|ú|û|ü)", "u".regex_latin_ci_list)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_create_a_string_with_the_latin_char_variations_for_the_letter_C
|
28
|
+
assert_equal("(c|ç)", "c".regex_latin_ci_list)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_should_create_a_string_with_the_latin_char_variations_for_the_letter_N
|
32
|
+
assert_equal("(n|ñ)", "n".regex_latin_ci_list)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_replace_all_chars_that_found_in_latin_variantion_list
|
36
|
+
expected = "r(e|è|é|ê|ë)g(e|è|é|ê|ë)xp (i|ì|í|î|ï)s p(o|ò|ó|ô|õ|ö)w(e|è|é|ê|ë)rf(u|ù|ú|û|ü)ll"
|
37
|
+
|
38
|
+
assert_equal expected, "regexp is powerfull".regex_latin_ci_list
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_should_returns_the_OR_metachar_if_or_options_was_passed
|
42
|
+
assert_equal "OR == |", "OR == ".regex_builder(:or => true)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_should_not_return_OR_when_the_OR_options_is_false
|
46
|
+
assert_equal "without OR", "without OR".regex_builder(:or => false)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_should_return_the_border_metachar_in_left_when_its_required_for_ruby
|
50
|
+
left = '\b'
|
51
|
+
expected = left + "string"
|
52
|
+
border = {:to => :ruby, :direction => :left}
|
53
|
+
|
54
|
+
assert_equal expected, "string".regex_builder(:border => border)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_should_return_the_border_metachar_in_right_when_its_required_for_ruby
|
58
|
+
right = '\b'
|
59
|
+
expected = "string" + right
|
60
|
+
border = {:to => :ruby, :direction => :right}
|
61
|
+
|
62
|
+
assert_equal expected, "string".regex_builder(:border => border)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_should_return_the_border_metachar_in_left_and_right_when_its_required_for_ruby
|
66
|
+
left = '\b'
|
67
|
+
right = '\b'
|
68
|
+
expected = left + "string" + right
|
69
|
+
border = {:to => :ruby, :direction => :both}
|
70
|
+
|
71
|
+
assert_equal expected, "string".regex_builder(:border => border)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_for_ruby_should_return_the_same_text_if_the_border_to_direction_is_invalid
|
75
|
+
text = "string"
|
76
|
+
border = {:to => :ruby}
|
77
|
+
|
78
|
+
assert_same text, text.regex_builder(:border => border)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_should_return_the_border_metachar_in_left_when_its_required_for_mysql
|
82
|
+
left = '[[:<:]]'
|
83
|
+
expected = left + "string"
|
84
|
+
border = {:to => :mysql, :direction => :left}
|
85
|
+
|
86
|
+
assert_equal expected, "string".regex_builder(:border => border)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_should_return_the_border_metachar_in_right_when_its_required_for_mysql
|
90
|
+
right = '[[:>:]]'
|
91
|
+
expected = "string" + right
|
92
|
+
border = {:to => :mysql, :direction => :right}
|
93
|
+
|
94
|
+
assert_equal expected, "string".regex_builder(:border => border)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_should_return_the_border_metachar_in_left_and_right_when_its_required_for_mysql
|
98
|
+
left = '[[:<:]]'
|
99
|
+
right = '[[:>:]]'
|
100
|
+
expected = left + "string" + right
|
101
|
+
border = {:to => :mysql, :direction => :both}
|
102
|
+
|
103
|
+
assert_equal expected, "string".regex_builder(:border => border)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_for_mysql_should_return_the_same_text_if_the_border_to_direction_is_invalid
|
107
|
+
text = "string"
|
108
|
+
border = {:to => :mysql, :direction => nil}
|
109
|
+
|
110
|
+
assert_same text, text.regex_builder(:border => border)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_should_return_a_mix_of_regexp_options
|
114
|
+
expected = "f.*(o|ò|ó|ô|õ|ö)"
|
115
|
+
assert_equal expected, "f*o".regex_builder(:any => true, :latin_chars_variations => true)
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class RegexMeToSearchTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@text = "ruby frameworks is so cool"
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_return_a_regex_for_ruby
|
10
|
+
assert_equal(/(foo|bar)/, "foo bar".regex_me_to_search_ruby)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_return_a_regex_for_mysql
|
14
|
+
assert_equal("(foo|bar)", "foo bar".regex_me_to_search_mysql)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_match_the_phrase_for_ruby
|
18
|
+
regexp = "ruby frameworks".regex_me_to_search_ruby(:exact_phrase => true)
|
19
|
+
assert_match(regexp, @text)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_match_independent_of_the_non_word_chars_between_the_words_phrase_for_ruby
|
23
|
+
text = "ruby - on - rails"
|
24
|
+
regexp = "ruby on rails".regex_me_to_search_ruby(:exact_phrase => true)
|
25
|
+
assert_match(regexp, text)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_should_match_the_text_fragments
|
29
|
+
regexp = "rub ool".regex_me_to_search_ruby(:exact_word => false)
|
30
|
+
assert_match(regexp, @text)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_should_not_match_the_text_fragments
|
34
|
+
regexp = "rub ool".regex_me_to_search_ruby(:exact_word => true)
|
35
|
+
assert_no_match(regexp, @text)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_should_just_match_exact_word
|
39
|
+
regexp = "ruby cool".regex_me_to_search_ruby(:exact_word => true)
|
40
|
+
assert_match(regexp, @text)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_should_match_because_the_word_finish_with_the_letter_A
|
44
|
+
text = "sinatra"
|
45
|
+
regexp = "*a".regex_me_to_search_ruby
|
46
|
+
assert_match(regexp, text)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_should_match_because_the_word_begin_with_the_letter_A
|
50
|
+
text = "assertions"
|
51
|
+
regexp = "a*".regex_me_to_search_ruby
|
52
|
+
assert_match(regexp, text)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_should_match_because_the_word_contain_all_required_letters
|
56
|
+
text = "sinatraaa"
|
57
|
+
regexp = "s*n*t*a".regex_me_to_search_ruby
|
58
|
+
assert_match(regexp, text)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_should_return_the_matched_sentencest
|
62
|
+
sentences = ['I like banana!', 'Do you like bonono?', 'foo bar', 'Regexp is cool']
|
63
|
+
regexp = "b*n*n* *l".regex_me_to_search_ruby
|
64
|
+
|
65
|
+
expected_sentences = ['I like banana!', 'Do you like bonono?', 'Regexp is cool']
|
66
|
+
matched_sentences = sentences.select { |sentence| sentence =~ regexp }
|
67
|
+
assert_equal(expected_sentences, matched_sentences)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_should_not_match_when_case_is_sensitive
|
71
|
+
text = "sinatra"
|
72
|
+
regexp = "SINATRA".regex_me_to_search_ruby(:case_insensitive => false)
|
73
|
+
assert_no_match(regexp, text)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_should_match_when_case_is_insensitive
|
77
|
+
text = "sinatra"
|
78
|
+
regexp = "SINATRA".regex_me_to_search_ruby(:case_insensitive => true)
|
79
|
+
assert_match(regexp, text)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_should_not_match_when_the_text_have_multilines
|
83
|
+
text = "d\na"
|
84
|
+
regexp = "d*a".regex_me_to_search_ruby(:multiline => false)
|
85
|
+
assert_no_match(regexp, text)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_should_match_when_the_text_have_multilines
|
89
|
+
text = "d\na"
|
90
|
+
regexp = "d*a".regex_me_to_search_ruby(:multiline => true)
|
91
|
+
assert_match(regexp, text)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_should_return_a_regex_to_mysql_with_borders
|
95
|
+
expected = "([[:<:]]foo[[:>:]])"
|
96
|
+
regexp = "foo".regex_me_to_search_mysql(:exact_word => true)
|
97
|
+
assert_equal(expected, regexp)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_should_return_a_exact_phrase_regex_to_mysql
|
101
|
+
expected = '[[:<:]]f(o|ò|ó|ô|õ|ö)(o|ò|ó|ô|õ|ö)[^0-9a-zA-Z\_]+b(a|à|á|â|ã|ä)r[[:>:]]'
|
102
|
+
regexp = "foo bar".regex_me_to_search_mysql(:exact_phrase => true)
|
103
|
+
assert_equal(expected, regexp)
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class TagsTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_should_cleaner_the_html_tag
|
6
|
+
assert_equal "", "<html>".html_tag_cleaner
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_not_clean_up_if_is_not_a_html_tag
|
10
|
+
assert_equal "<serradura>", "<serradura>".html_tag_cleaner
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_clean_up_all_tags_and_just_keep_the_text
|
14
|
+
assert_equal "Serradura Labs", "<a href='http://blog.serraduralabs.com'>Serradura Labs</a>".html_tag_cleaner
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_clean_up_anything_resembling_a_tag
|
18
|
+
assert_equal "", "<a></b></serradura><></>".tag_cleaner
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_should_only_clean_up_complete_tags_patterns
|
22
|
+
assert_equal "<\o/>", "<a><</b>\</serradura>o<>/></>".tag_cleaner
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: string_utility_belt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Rodrigo Serradura
|
@@ -15,12 +15,12 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
18
|
+
date: 2011-07-07 00:00:00 Z
|
20
19
|
dependencies: []
|
21
20
|
|
22
|
-
description:
|
21
|
+
description: Adiciona novas funcionalidades para strings
|
23
22
|
email:
|
23
|
+
- rserradura@gmail.com
|
24
24
|
executables: []
|
25
25
|
|
26
26
|
extensions: []
|
@@ -28,19 +28,27 @@ extensions: []
|
|
28
28
|
extra_rdoc_files: []
|
29
29
|
|
30
30
|
files:
|
31
|
-
-
|
32
|
-
-
|
33
|
-
-
|
31
|
+
- .gitignore
|
32
|
+
- Gemfile
|
33
|
+
- Gemfile.lock
|
34
|
+
- README.markdown
|
35
|
+
- Rakefile
|
34
36
|
- lib/string_utility_belt.rb
|
35
|
-
- lib/
|
36
|
-
- lib/
|
37
|
-
- lib/
|
38
|
-
- lib/
|
37
|
+
- lib/string_utility_belt/entities.rb
|
38
|
+
- lib/string_utility_belt/general.rb
|
39
|
+
- lib/string_utility_belt/match_rank.rb
|
40
|
+
- lib/string_utility_belt/regex_me_helper.rb
|
41
|
+
- lib/string_utility_belt/regex_me_to_search.rb
|
42
|
+
- lib/string_utility_belt/tags.rb
|
39
43
|
- lib/string_utility_belt/version.rb
|
40
|
-
-
|
41
|
-
- string_utility_belt.
|
42
|
-
|
43
|
-
|
44
|
+
- test/string_utility_belt/entities_test.rb
|
45
|
+
- test/string_utility_belt/general_test.rb
|
46
|
+
- test/string_utility_belt/match_rank_test.rb
|
47
|
+
- test/string_utility_belt/regex_me_helper_test.rb
|
48
|
+
- test/string_utility_belt/regex_me_to_search_test.rb
|
49
|
+
- test/string_utility_belt/tags_test.rb
|
50
|
+
- test/test_helper.rb
|
51
|
+
homepage: ""
|
44
52
|
licenses: []
|
45
53
|
|
46
54
|
post_install_message:
|
@@ -68,10 +76,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
76
|
version: "0"
|
69
77
|
requirements: []
|
70
78
|
|
71
|
-
rubyforge_project:
|
72
|
-
rubygems_version: 1.
|
79
|
+
rubyforge_project: string_utility_belt
|
80
|
+
rubygems_version: 1.8.2
|
73
81
|
signing_key:
|
74
82
|
specification_version: 3
|
75
|
-
summary:
|
83
|
+
summary: Metodos uteis para strings
|
76
84
|
test_files: []
|
77
85
|
|
data/lib/general/general.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
|
2
|
-
module General
|
3
|
-
|
4
|
-
def words
|
5
|
-
self.scan(/\w[\w\'\-]*/)
|
6
|
-
end
|
7
|
-
|
8
|
-
def simple_space
|
9
|
-
self.strip.gsub(/\s+/, " ")
|
10
|
-
end
|
11
|
-
|
12
|
-
def simple_space!
|
13
|
-
self.strip.gsub!(/\s+/, " ")
|
14
|
-
end
|
15
|
-
|
16
|
-
def have_this_words? words_to_match, options = {}
|
17
|
-
helper_have_this_words? words_to_match, options do |string, word, options|
|
18
|
-
return false if (string !~ word.regex_me_to_search_ruby(:exact_word => options[:exact_word], :case_insensitive => options[:case_insensitive], :latin_chars_variation => options[:latin_chars_variation]))
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def not_have_this_words? words_to_match, options = {}
|
23
|
-
helper_have_this_words? words_to_match, options do |string, word, options|
|
24
|
-
return false if (string =~ word.regex_me_to_search_ruby(:exact_word => options[:exact_word], :case_insensitive => options[:case_insensitive], :latin_chars_variation => options[:latin_chars_variation]))
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
def helper_have_this_words? words_to_match, options = {}
|
30
|
-
for word in words_to_match
|
31
|
-
yield self, word, options
|
32
|
-
end
|
33
|
-
return true
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
|
2
|
-
require "rubygems" if RUBY_VERSION < "1.9"
|
3
|
-
require "htmlentities"
|
4
|
-
|
5
|
-
module Entities
|
6
|
-
|
7
|
-
def decode_entities
|
8
|
-
coder = HTMLEntities.new
|
9
|
-
coder.decode(self)
|
10
|
-
end
|
11
|
-
|
12
|
-
def decode_entities_and_cleaner
|
13
|
-
decode_entities.tag_cleaner
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
|
2
|
-
module Tags
|
3
|
-
|
4
|
-
def tag_cleaner
|
5
|
-
self.gsub(/<\/?[^>]*>/, "")
|
6
|
-
end
|
7
|
-
|
8
|
-
def html_tag_cleaner
|
9
|
-
self.gsub(/<\/?(a|p|abbr|acronym|address|applet|area|b|base|basefont|bdo|big|blockquote|body|br|button|caption|center|cite|code|col|colgroup|dd|del|dfn|dir|div|dl|dt|em|fieldset|font|form|frame|frameset|h6|head|hr|html|i|iframe|img|input|ins|isindex|kbd|label|legend|li|link|map|menu|meta|noframes|noscript|object)[^>]+??>/im, "")
|
10
|
-
# TAGs disponíveis até 09/2010 - FONTE: http://www.w3schools.com/tags/default.asp
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
|
2
|
-
class String
|
3
|
-
|
4
|
-
LATIN_CHARS_VARIATION = ["[aàáâãä]", "[eèéêë]", "[iìíîï]", "[oòóôõö]", "[uùúûü]", "[cçÇ]", "[ñÑ]"]
|
5
|
-
|
6
|
-
def regex_latin_ci_list
|
7
|
-
|
8
|
-
memo = ""
|
9
|
-
self.each_char do |char|
|
10
|
-
|
11
|
-
variation_found = false
|
12
|
-
|
13
|
-
for char_variation in LATIN_CHARS_VARIATION
|
14
|
-
|
15
|
-
match = eval("/#{char_variation}/")
|
16
|
-
|
17
|
-
if (char =~ match)
|
18
|
-
memo.insert(-1, char_variation)
|
19
|
-
variation_found = true
|
20
|
-
break
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
memo.insert(-1, char) unless variation_found
|
25
|
-
end
|
26
|
-
|
27
|
-
self.replace(memo)
|
28
|
-
end
|
29
|
-
|
30
|
-
def regex_builder options={}
|
31
|
-
|
32
|
-
self.gsub!(/\*/,'.*') if options[:any]
|
33
|
-
|
34
|
-
regex_latin_ci_list if options[:latin_chars_variation]
|
35
|
-
|
36
|
-
border_me(options[:border][:to],
|
37
|
-
options[:border][:direction]) if options[:border]
|
38
|
-
|
39
|
-
insert_OR_in_right unless options[:delete_or]
|
40
|
-
|
41
|
-
self
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
def insert_OR_in_right
|
46
|
-
self.insert(-1, "|")
|
47
|
-
end
|
48
|
-
|
49
|
-
def border_me border_to, direction
|
50
|
-
border = define_border_metachar(border_to)
|
51
|
-
|
52
|
-
case direction
|
53
|
-
when :left
|
54
|
-
self.insert(0, border[:left])
|
55
|
-
when :right
|
56
|
-
self.insert(-1, border[:right])
|
57
|
-
when :both
|
58
|
-
self.insert(0, border[:left]).insert(-1, border[:right])
|
59
|
-
when nil
|
60
|
-
self
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def define_border_metachar border_to
|
65
|
-
case border_to
|
66
|
-
when :ruby
|
67
|
-
{:left => '\b' , :right => '\b'}
|
68
|
-
when :mysql
|
69
|
-
{:left => '[[:<:]]', :right => '[[:>:]]'}
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|