mightystring 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +10 -0
- data/README +20 -0
- data/bin/ms-striphtml +36 -0
- data/lib/mightystring.rb +30 -0
- data/lib/mightystring/string_at.rb +16 -0
- data/lib/mightystring/string_del.rb +49 -0
- data/lib/mightystring/string_index_all.rb +27 -0
- data/lib/mightystring/string_matchpci.rb +16 -0
- data/lib/mightystring/string_stripbyac.rb +28 -0
- data/lib/mightystring/strip_html.rb +149 -0
- data/lib/mightystring/version.rb +3 -0
- data/test/test_ms.rb +49 -0
- metadata +80 -0
data/LICENSE
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2012 Daniel P. Clark & 6ft Dan(TM)
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
10
|
+
|
data/README
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
MightyString
|
2
|
+
by Daniel P. Clark
|
3
|
+
|
4
|
+
Description: Add Array functionality to Strings and other tools for Strings: Matching, Indexing, Substitution, Deletion, and more.
|
5
|
+
|
6
|
+
Pain points this solves.
|
7
|
+
* After working with Python, it's obvious Ruby strings are lacking... so lets spiff them up.
|
8
|
+
* Strings are Arrays... I mean really, think about it. This works toward making Strings function as Arrays.
|
9
|
+
* Also this provides additional string tools under MightyString... like strip_html.
|
10
|
+
|
11
|
+
My method.
|
12
|
+
* I believe code should be beautiful, simple, and well rounded. No animals were harmed in ... err I mean no regex was used in the making of this library.
|
13
|
+
|
14
|
+
Some tools to consider here.
|
15
|
+
* MightyString::HTML.strip_html provides a more ideal HTML to ASCII formatting output. This is an advanced block "filtering" module. It works very well with, currently, extremely rare cases that fall through it's fingers. Regardless it's beautiful, and will strive to be more so.
|
16
|
+
|
17
|
+
Advanced detail.
|
18
|
+
* Look at the test/test_ms.rb for case usages of each feature.
|
19
|
+
|
20
|
+
Follow this project and contribute via github http://www.github.com/danielpclark/mightystring
|
data/bin/ms-striphtml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'getoptlong'
|
4
|
+
begin
|
5
|
+
require 'mightystring'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'mightystring'
|
9
|
+
end
|
10
|
+
|
11
|
+
include MightyString
|
12
|
+
opts = GetoptLong.new(
|
13
|
+
["--license", "-l", GetoptLong::NO_ARGUMENT],
|
14
|
+
["--test", "-t", GetoptLong::NO_ARGUMENT],
|
15
|
+
["--help", "-h", GetoptLong::NO_ARGUMENT]
|
16
|
+
)
|
17
|
+
opts.each do |opt, arg|
|
18
|
+
case opt
|
19
|
+
when "--help"
|
20
|
+
puts "Yes. You do indeed need help. Go seek it."
|
21
|
+
#RDoc::usage
|
22
|
+
when "--test"
|
23
|
+
#Strip_HTML.test = true
|
24
|
+
HTML.testCase
|
25
|
+
when "--license"
|
26
|
+
#Strip_HTML.license = true
|
27
|
+
HTML.license
|
28
|
+
end
|
29
|
+
end
|
30
|
+
if ARGV.any? { |s| s.downcase.include?('.htm') } then
|
31
|
+
ARGV.each do |s|
|
32
|
+
if s.downcase.include?('.htm') and File.exists?(s)
|
33
|
+
puts HTML.strip_html( File.open(s, "rb").read )
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/mightystring.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
$: << File.join(File.dirname(__FILE__), "/mightystring")
|
2
|
+
require 'mightystring/string_matchpci'
|
3
|
+
require 'mightystring/string_index_all'
|
4
|
+
require 'mightystring/string_at'
|
5
|
+
require 'mightystring/string_del'
|
6
|
+
require 'mightystring/string_stripbyac'
|
7
|
+
require 'mightystring/strip_html'
|
8
|
+
require 'mightystring/version'
|
9
|
+
|
10
|
+
# Author: Daniel P. Clark / 6ft Dan(TM) Website: http://www.6ftdan.com
|
11
|
+
|
12
|
+
=begin LICENSE
|
13
|
+
MightyString is licensed under 'The MIT License (MIT)'
|
14
|
+
|
15
|
+
Copyright (c) 2012 Daniel P. Clark & 6ft Dan(TM)
|
16
|
+
|
17
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
18
|
+
|
19
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
20
|
+
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
|
22
|
+
=end
|
23
|
+
|
24
|
+
class String
|
25
|
+
include At::String
|
26
|
+
include Del::String
|
27
|
+
include Index_All::String
|
28
|
+
include Match_PCI::String
|
29
|
+
include StripbyAC::String
|
30
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Part of MightyString
|
2
|
+
# by Daniel P. Clark
|
3
|
+
# webmaster@6ftdan.com
|
4
|
+
|
5
|
+
# At
|
6
|
+
module At
|
7
|
+
module String
|
8
|
+
# At : Returns string instead of char number.
|
9
|
+
def at(in_srch = nil)
|
10
|
+
if in_srch.is_a?(Integer)
|
11
|
+
return self[in_srch..in_srch]
|
12
|
+
end
|
13
|
+
return nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Part of MightyString
|
2
|
+
# by Daniel P. Clark
|
3
|
+
# webmaster@6ftdan.com
|
4
|
+
|
5
|
+
# Del : Delete by index/slice
|
6
|
+
module Del
|
7
|
+
module String
|
8
|
+
# Del : Delete by index/slice
|
9
|
+
def del(in_srch = nil)
|
10
|
+
if not in_srch.nil?
|
11
|
+
if in_srch.is_a?(Range) and in_srch.first.is_a?(Integer) and in_srch.last.is_a?(Integer)
|
12
|
+
if not self[in_srch.first].nil? and not self[in_srch.last-1].nil?
|
13
|
+
if in_srch.first < 0
|
14
|
+
in_srch = self[0..in_srch.first-1].length..in_srch.last
|
15
|
+
end
|
16
|
+
if in_srch.last < 0
|
17
|
+
in_srch = in_srch.first..self[0..in_srch.last].length
|
18
|
+
end
|
19
|
+
if in_srch.first < in_srch.last
|
20
|
+
if in_srch.first == 0
|
21
|
+
return self[in_srch.last+1..-1]
|
22
|
+
elsif in_srch.last == self.length
|
23
|
+
return self[0..in_srch.first-1]
|
24
|
+
else
|
25
|
+
return self[0..in_srch.first-1] + self[in_srch.last+1..-1]
|
26
|
+
end
|
27
|
+
else
|
28
|
+
raise Exception.new("Invalid Range Provided!")
|
29
|
+
end
|
30
|
+
else
|
31
|
+
raise Exception.new("Index Out of Range!")
|
32
|
+
end
|
33
|
+
elsif in_srch.is_a?(Integer) and -self.length-1 < in_srch and in_srch < self.length
|
34
|
+
if in_srch == -1
|
35
|
+
in_srch = self.length-1
|
36
|
+
elsif in_srch < -1 and not self[in_srch].nil?
|
37
|
+
in_srch = self.length + in_srch
|
38
|
+
end
|
39
|
+
if in_srch == 0
|
40
|
+
return self[(in_srch+1)..self.length]
|
41
|
+
else
|
42
|
+
return self[0..in_srch-1] + self[(in_srch+1)..self.length]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
return nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Part of MightyString
|
2
|
+
# by Daniel P. Clark
|
3
|
+
# webmaster@6ftdan.com
|
4
|
+
|
5
|
+
# Index_All
|
6
|
+
module Index_All
|
7
|
+
module String
|
8
|
+
# find_all(search string): Returns indexes of search string as an index array.
|
9
|
+
def index_all(in_srch = "")
|
10
|
+
in_srch = in_srch.to_s
|
11
|
+
if not in_srch.empty?
|
12
|
+
arr_indexes = []
|
13
|
+
srch_index = self.rindex(in_srch)
|
14
|
+
while not srch_index.nil? do
|
15
|
+
tmpStr = self[0..srch_index-1]
|
16
|
+
arr_indexes += [srch_index] # Put it in the list
|
17
|
+
if srch_index == 0
|
18
|
+
srch_index = nil
|
19
|
+
else
|
20
|
+
srch_index = tmpStr.rindex(in_srch)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
return arr_indexes.reverse
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Part of MightyString
|
2
|
+
# by Daniel P. Clark
|
3
|
+
# webmaster@6ftdan.com
|
4
|
+
|
5
|
+
# Match Partial Case-Insensitive
|
6
|
+
module Match_PCI
|
7
|
+
module String
|
8
|
+
# Match Partial Case-Insensitive: Usage: "My string has this?".matchpci('RinG') => true
|
9
|
+
def match_pci(in_srch = "")
|
10
|
+
if not in_srch.empty?
|
11
|
+
return !self.find_all{|item| item.downcase.include?(in_srch.downcase)}.empty?
|
12
|
+
end
|
13
|
+
return false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Part of MightyString
|
2
|
+
# by Daniel P. Clark
|
3
|
+
# webmaster@6ftdan.com
|
4
|
+
|
5
|
+
# Example acceptable charachters = (Range.new('a','z').to_a + Range.new('A','Z').to_a + Range.new('0','9').to_a + ['.','-','_',"'",'"',',']).flatten
|
6
|
+
|
7
|
+
# Strip by Acceptable Characters
|
8
|
+
module StripbyAC
|
9
|
+
module String
|
10
|
+
# Strip by Acceptable Characters : String.stripbyac(charlist) => Copy of New String (removes any character not in list)
|
11
|
+
def strip_byac(acceptchars)
|
12
|
+
if not acceptchars.nil?
|
13
|
+
if acceptchars.is_a?(String)
|
14
|
+
return self.split('').map!{|x| if acceptchars.split('').include?(x); x end }.join
|
15
|
+
elsif acceptchars.is_a?(Array)
|
16
|
+
return self.split('').map!{|x| if acceptchars.include?(x); x end }.join
|
17
|
+
elsif acceptchars.respond_to?(:[])
|
18
|
+
acceptchars = acceptchars.to_a
|
19
|
+
return self.split('').map!{|x| if acceptchars.include?(x); x end }.join
|
20
|
+
else
|
21
|
+
raise "#{puts acceptchars.class}"
|
22
|
+
end
|
23
|
+
else
|
24
|
+
raise StandardError.new('You must include a list of acceptable characters for this string in stripbyac(acceptchars)!')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
|
2
|
+
# APP_VERSION = '0.1 11-27-2012'
|
3
|
+
|
4
|
+
# Mighty String - Strip HTML
|
5
|
+
# Ruby should be easy to read, regex is not. I believe string block handling can be done better than rough regex'ing.
|
6
|
+
#
|
7
|
+
# TODO *FIXME* A rare href exception gets by, as well as some comment cases. 0.1 11-27-2012 "Release Version"
|
8
|
+
#
|
9
|
+
# Ver 0.1 11-27-2012 "Release Version"
|
10
|
+
# - Modularized and Gemified
|
11
|
+
# - Fixed mathmatical exceptions. Code is completely functional with test case.
|
12
|
+
#
|
13
|
+
# Ver Pre_0.3.0 8-7-2012
|
14
|
+
# - Added String modules for a healthy and useful String library
|
15
|
+
# - Finished mathmatical and generic & exceptions
|
16
|
+
#
|
17
|
+
# Ver Pre_0.2.1
|
18
|
+
# - Fixed indexing problem when only 1 of two cases where 'paired'. Such as '<' and not '>'. It died previously on nil.
|
19
|
+
# - Added test case
|
20
|
+
#
|
21
|
+
# Ver Pre_0.2
|
22
|
+
# - Added command line html file processing
|
23
|
+
# - Added case insensitivity for HTML snippets
|
24
|
+
#
|
25
|
+
# Ver Pre_0.1
|
26
|
+
# - HTML tag stripper with ASCII output
|
27
|
+
|
28
|
+
Strip_HTML_License = "
|
29
|
+
|
30
|
+
MightyString is licensed under 'The MIT License (MIT)'
|
31
|
+
|
32
|
+
Copyright (c) 2012 Daniel P. Clark & 6ft Dan(TM)
|
33
|
+
|
34
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
35
|
+
|
36
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
37
|
+
|
38
|
+
THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
|
39
|
+
# REQUIRE #
|
40
|
+
begin
|
41
|
+
require 'string_match_pci'
|
42
|
+
require 'string_index_all'
|
43
|
+
rescue LoadError # For test-unit
|
44
|
+
$: << File.join(File.dirname(__FILE__), "/../lib")
|
45
|
+
$: << File.join(File.dirname(__FILE__), "/../lib/mightystring")
|
46
|
+
require 'string_matchpci'
|
47
|
+
require 'string_index_all'
|
48
|
+
end
|
49
|
+
# END REQUIRE #
|
50
|
+
class String
|
51
|
+
include Index_All::String
|
52
|
+
include Match_PCI::String
|
53
|
+
end
|
54
|
+
|
55
|
+
module MightyString
|
56
|
+
module HTML
|
57
|
+
# Define some generic rules here ***
|
58
|
+
# ---- COOL note: you can insert ASCII color escape code rules here... like for href then blue and for /a then plain
|
59
|
+
def self.html_to_text_codes
|
60
|
+
{"""=>"'","br"=>"\n","'" => "'", "td" => " | ", " " => " ", "™" => "(TM)", "©" => "(c)"} # replace html segment and insert plan text equivalent
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.math_by_space
|
64
|
+
true # if this is set then < followed by a space is considered not a html tag, like wise > with a space beforehand
|
65
|
+
end
|
66
|
+
|
67
|
+
# End define generic rules ***
|
68
|
+
|
69
|
+
def self.html_math_exceptions(in_str = "")
|
70
|
+
if in_str["< "] or in_str["& "]
|
71
|
+
return 1 # Execption found at beginning
|
72
|
+
elsif in_str["&"] and in_str[";"] and (in_str[" "] or in_str.length > 7) # Shouldn't have spaces in html &code;s or be greater than 7 in length
|
73
|
+
return 2 # Exception found for both
|
74
|
+
else
|
75
|
+
return 0
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
# strip sequence out ( master string, sequence to remove, any characters to swap inplace this for that )
|
81
|
+
def self.strip_first_seq( mstr = "", mseq = "", cmpchar = self.html_to_text_codes )
|
82
|
+
if not cmpchar.empty? and cmpchar.keys.any? {|mkey| mseq.match_pci(mkey) } # keys exist and one of the keys match
|
83
|
+
cmpchar.each_key { |mkey|
|
84
|
+
if mseq.match_pci(mkey)
|
85
|
+
mstr = mstr[0,mstr.index(mseq)] + cmpchar[mkey] + mstr[(mstr.index(mseq)+mseq.length)..-1]
|
86
|
+
end
|
87
|
+
}
|
88
|
+
elsif mstr.index(mseq)
|
89
|
+
mstr = mstr[0,mstr.index(mseq)] + mstr[(mstr.index(mseq)+mseq.length)..-1]
|
90
|
+
end
|
91
|
+
return mstr
|
92
|
+
end
|
93
|
+
|
94
|
+
# Pick tags/blocks of string to remove (ex: "&", ";" like in """ can become "" or "'" if rules set))
|
95
|
+
def self.strip_html( htmlstr = "", xarg = [["<",">"],["&",";"]] ) # xarg start, end
|
96
|
+
xarg.each { |g|
|
97
|
+
sh_endpoints = htmlstr.index_all(g[1])
|
98
|
+
if sh_endpoints.nil?
|
99
|
+
break
|
100
|
+
end
|
101
|
+
sh_end = htmlstr.rindex(g[1])
|
102
|
+
sh_start = htmlstr.rindex(g[0])
|
103
|
+
while !!sh_end and !!sh_start do
|
104
|
+
if sh_end > sh_start
|
105
|
+
sh_seq = htmlstr[sh_start,sh_end - sh_start + 1]
|
106
|
+
until sh_seq.count(g[1]) == 1 do # until we've selected only the inner block
|
107
|
+
sh_end = htmlstr[0,sh_end-1].rindex(g[1])
|
108
|
+
sh_seq = htmlstr[sh_start,sh_end - sh_start + 1]
|
109
|
+
end
|
110
|
+
if not (math_by_space and not html_math_exceptions(htmlstr[sh_start,sh_end - sh_start + 1]) == 0)
|
111
|
+
htmlstr = strip_first_seq( htmlstr, htmlstr[sh_start,sh_end - sh_start + 1])
|
112
|
+
else
|
113
|
+
sh_end = sh_end - 1
|
114
|
+
end
|
115
|
+
else
|
116
|
+
sh_start = sh_start - 1
|
117
|
+
end
|
118
|
+
sh_end = htmlstr[0..sh_end].rindex(g[1])
|
119
|
+
sh_start = htmlstr[0..sh_start].rindex(g[0])
|
120
|
+
end
|
121
|
+
}
|
122
|
+
return htmlstr
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.testCase
|
126
|
+
pagesample = "<html><body>This code primarily removes (less than)tags(greater than) and (amperstand)code(semicolon).<br>This default behavior can be modified to fit your needs.<br>4>3 doesn't pair up, so it's visible.<br>As well as this with a space 4 > 3.<br>The opposite is 3 < 4. Can you see me?<br>These following punctions don't get removed because they are out of matching order. ';and&'.<br>< This is visible because of the first space before the less than symbol. ><br>&This shows because it's longer then characters in length and has a space in it.;<br><br><table><tr><td>My Box Table</td></tr></table> <!-- <div>Old HTML commented out. This is a unique case.<br>The code finds the innermost blocks and removes them outwards. So something like '< !-- < tag >' or '< /tag > -- >' won't raise an error.<br>(I added the spaces so you can still see the ouput print.)</div> --><br><br><h1>Ruby is quite nice!</h1><br><a href='_blank'>http://www.6ftdan.com</a></body></html>"
|
127
|
+
puts pagesample
|
128
|
+
puts
|
129
|
+
puts " * - * - * - Before test is above. - * - * - after striphtml follows - * - * - *"
|
130
|
+
puts
|
131
|
+
puts strip_html(pagesample)
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.license
|
135
|
+
license = "Mighty_String::Strip_HTML is licensed under 'The MIT License (MIT)'
|
136
|
+
|
137
|
+
Copyright (c) 2012 Daniel P. Clark & 6ft Dan(TM)
|
138
|
+
|
139
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
140
|
+
|
141
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
142
|
+
|
143
|
+
THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
|
144
|
+
puts
|
145
|
+
puts license
|
146
|
+
puts
|
147
|
+
end
|
148
|
+
end # module Strip_HTML
|
149
|
+
end # MightyString
|
data/test/test_ms.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
$: << File.join(File.dirname(__FILE__), "/../lib")
|
2
|
+
$: << File.join(File.dirname(__FILE__), "/../lib/mightystring")
|
3
|
+
require 'test/unit'
|
4
|
+
require 'mightystring'
|
5
|
+
|
6
|
+
class TestMightyString < Test::Unit::TestCase
|
7
|
+
def test_at
|
8
|
+
assert "abc".at(0) == "a"
|
9
|
+
assert "0123456789".at(-1) == "9"
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_del
|
13
|
+
assert "abc".del(1) == "ac"
|
14
|
+
assert "0123456789".del(0..2) == "3456789"
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_index_all
|
18
|
+
assert "012324507654301243".index_all 0 == [0,7,13]
|
19
|
+
assert "the apple is the best fruit in the world".index_all "the" == [0, 13, 31]
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_matchpci
|
23
|
+
assert "<TD>".match_pci("td")
|
24
|
+
assert "<TD>".match_pci("><") == false
|
25
|
+
assert "Principle".match_pci("rINCi")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_stripbyac
|
29
|
+
assert "qa2ws3ed4rf5tg6yh7uj8ik9ol".strip_byac( Range.new( "0", "9" ).to_a ) == "23456789"
|
30
|
+
|
31
|
+
custRange = (Range.new('a','z').to_a + Range.new('A','Z').to_a + [" "]).flatten
|
32
|
+
assert "<html><body> Content </body></html>".strip_byac(custRange) == "htmlbody Content bodyhtml"
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_strip_first_seq
|
36
|
+
assert MightyString::HTML.strip_first_seq("APPLES n APPLES ARE Yummy!","APPLES",{"APPLES" => "COWS"}) == "COWS n APPLES ARE Yummy!"
|
37
|
+
assert MightyString::HTML.strip_first_seq("Cows Cows and more Cows!","Cows", {"Cows" => "Winner"}) == "Winner Cows and more Cows!"
|
38
|
+
assert MightyString::HTML.strip_first_seq(" ---- APPLES &nbps;", " " ) == " ---- APPLES &nbps;"
|
39
|
+
assert MightyString::HTML.strip_first_seq("™ ---- ™ TradeMark ™", "™" ) == "(TM) ---- ™ TradeMark ™"
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_strip_html
|
43
|
+
assert MightyString::HTML.strip_html("<html>") == ""
|
44
|
+
assert MightyString::HTML.strip_html("<table><tr><td>Piped sides.</td></tr></table>") == " | Piped sides. | "
|
45
|
+
assert MightyString::HTML.strip_html("Hello<br>World!") == "Hello\nWorld!"
|
46
|
+
assert MightyString::HTML.strip_html("<p>"Quoted" Copyright © TradeMark ™</p>") == "'Quoted' Copyright (c) TradeMark (TM)"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mightystring
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Daniel P. Clark / 6ftDan(TM)
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-10-26 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Array functionality in Strings as well as Matching, Indexing, Substitution, Deletion, and more.
|
22
|
+
email: webmaster@6ftdan.com
|
23
|
+
executables:
|
24
|
+
- ms-striphtml
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README
|
29
|
+
files:
|
30
|
+
- bin/ms-striphtml
|
31
|
+
- lib/mightystring/string_at.rb
|
32
|
+
- lib/mightystring/strip_html.rb
|
33
|
+
- lib/mightystring/string_index_all.rb
|
34
|
+
- lib/mightystring/string_stripbyac.rb
|
35
|
+
- lib/mightystring/string_matchpci.rb
|
36
|
+
- lib/mightystring/string_del.rb
|
37
|
+
- lib/mightystring/version.rb
|
38
|
+
- lib/mightystring.rb
|
39
|
+
- test/test_ms.rb
|
40
|
+
- README
|
41
|
+
- LICENSE
|
42
|
+
homepage: http://www.github.com/danielpclark/mightystring
|
43
|
+
licenses:
|
44
|
+
- The MIT License (MIT)
|
45
|
+
post_install_message: |-
|
46
|
+
Enjoy MightyString! Your strings are now more powerful.
|
47
|
+
Peak around inside String and MightyString.
|
48
|
+
http://www.github.com/danielpclark/mightystring
|
49
|
+
rdoc_options:
|
50
|
+
- --main
|
51
|
+
- README
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.24
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Strings (are) Arrays & Matching, Indexing, Substitution, Deletion, and more.
|
79
|
+
test_files:
|
80
|
+
- test/test_ms.rb
|