mightystring 0.1.4 → 0.1.5.b
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +10 -10
- data/{README → README.md} +30 -20
- data/bin/ms-striphtml +36 -36
- data/lib/mightystring.rb +57 -30
- data/lib/mightystring/string_at.rb +26 -16
- data/lib/mightystring/string_del.rb +51 -51
- data/lib/mightystring/string_each.rb +24 -0
- data/lib/mightystring/string_fetch.rb +13 -0
- data/lib/mightystring/string_find.rb +19 -0
- data/lib/mightystring/string_first.rb +13 -0
- data/lib/mightystring/string_index_all.rb +27 -27
- data/lib/mightystring/string_join.rb +13 -0
- data/lib/mightystring/string_last.rb +13 -0
- data/lib/mightystring/string_map.rb +19 -0
- data/lib/mightystring/string_match_pci.rb +16 -0
- data/lib/mightystring/string_method_missing.rb +25 -0
- data/lib/mightystring/string_pop.rb +15 -0
- data/lib/mightystring/string_push.rb +13 -0
- data/lib/mightystring/string_shift.rb +15 -0
- data/lib/mightystring/string_sort.rb +17 -0
- data/lib/mightystring/{string_stripbyac.rb → string_strip_byac.rb} +28 -28
- data/lib/mightystring/string_unshift.rb +13 -0
- data/lib/mightystring/strip_html.rb +143 -149
- data/lib/mightystring/version.rb +3 -3
- data/test/test_ms.rb +53 -50
- metadata +32 -21
- data/lib/mightystring/string_matchpci.rb +0 -16
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f81d10d6170f550308207e1db2ff1250969c1649
|
4
|
+
data.tar.gz: e38c7eefd1a4ef0c3e9d39c055d9a666c8df8a5e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c75de5c7c086b57a3e40ea2ce1d6c2d9138a7279ee4a02c5fe31d4311f2264dd1ff9cb6e380f7bd8062362cd2e50e9cdb58892de92106d30498e1de2ce6e6bf2
|
7
|
+
data.tar.gz: 6d46ef97a9ce7836f160dea1934fb914b0ddf214ed42ec2f25eb4b38cf5fabf95fbbec0c192b5516a1a81de616c30bd8ab61151e21e0b0905a3a01f700ef7f2e
|
data/LICENSE
CHANGED
@@ -1,10 +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
|
-
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2012-2014 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 → README.md}
RENAMED
@@ -1,20 +1,30 @@
|
|
1
|
-
MightyString
|
2
|
-
by Daniel P. Clark
|
3
|
-
|
4
|
-
Description
|
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.
|
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
|
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. I've come to expect strings to be handled easily like arrays. There's no reason why not. So I've brought that reality to Ruby.
|
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
|
21
|
+
<br />
|
22
|
+
<br />
|
23
|
+
# Goal for 0.2.0
|
24
|
+
*Have Array and String interchangable. Same errors, same results.*
|
25
|
+
<br />
|
26
|
+
<br />
|
27
|
+
Version <strong>0.1.4</strong><br />
|
28
|
+
* Added string input acceptance to del<br />
|
29
|
+
Example:<br />
|
30
|
+
<code>"12#34#56#78".del("#") # => "12345678"</code></p>
|
data/bin/ms-striphtml
CHANGED
@@ -1,36 +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
|
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
CHANGED
@@ -1,30 +1,57 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
1
|
+
require_relative 'mightystring/string_at'
|
2
|
+
require_relative 'mightystring/string_del'
|
3
|
+
require_relative 'mightystring/string_each'
|
4
|
+
require_relative 'mightystring/string_fetch'
|
5
|
+
require_relative 'mightystring/string_find'
|
6
|
+
require_relative 'mightystring/string_first'
|
7
|
+
require_relative 'mightystring/string_index_all'
|
8
|
+
require_relative 'mightystring/string_join'
|
9
|
+
require_relative 'mightystring/string_last'
|
10
|
+
require_relative 'mightystring/string_map'
|
11
|
+
require_relative 'mightystring/string_match_pci'
|
12
|
+
require_relative 'mightystring/string_pop'
|
13
|
+
require_relative 'mightystring/string_push'
|
14
|
+
require_relative 'mightystring/string_shift'
|
15
|
+
require_relative 'mightystring/string_sort'
|
16
|
+
require_relative 'mightystring/string_strip_byac'
|
17
|
+
require_relative 'mightystring/string_unshift'
|
18
|
+
require_relative 'mightystring/strip_html'
|
19
|
+
require_relative 'mightystring/version'
|
20
|
+
require_relative 'mightystring/string_method_missing'
|
21
|
+
|
22
|
+
class String
|
23
|
+
include At::String
|
24
|
+
include Del::String
|
25
|
+
include Each::String
|
26
|
+
include Fetch::String
|
27
|
+
include Find::String
|
28
|
+
include First::String
|
29
|
+
include Index_All::String
|
30
|
+
include Join::String
|
31
|
+
include Last::String
|
32
|
+
include Map::String
|
33
|
+
include Match_PCI::String
|
34
|
+
include Pop::String
|
35
|
+
include Push::String
|
36
|
+
include Shift::String
|
37
|
+
include Sort::String
|
38
|
+
include Strip_byAC::String
|
39
|
+
include UnShift::String
|
40
|
+
include MethodMissing::String
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
class Array
|
45
|
+
# To fix a bug that our method_missing creates
|
46
|
+
# we need to set a MAXIMUM for FLATTEN
|
47
|
+
alias_method :_old_flatten, :flatten
|
48
|
+
alias_method :_old_flatten!, :flatten!
|
49
|
+
|
50
|
+
def flatten(level = 99)
|
51
|
+
_old_flatten(level)
|
52
|
+
end
|
53
|
+
|
54
|
+
def flatten!(level = 99)
|
55
|
+
_old_flatten!(level)
|
56
|
+
end
|
57
|
+
end
|
@@ -1,16 +1,26 @@
|
|
1
|
-
# Part of MightyString
|
2
|
-
# by Daniel P. Clark
|
3
|
-
# webmaster@6ftdan.com
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
1
|
+
# Part of MightyString
|
2
|
+
# by Daniel P. Clark
|
3
|
+
# webmaster@6ftdan.com
|
4
|
+
require 'forwardable'
|
5
|
+
|
6
|
+
# At
|
7
|
+
module At
|
8
|
+
module String
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
def self.included(base)
|
12
|
+
base.send :extend, Forwardable
|
13
|
+
end
|
14
|
+
|
15
|
+
# At : Returns string instead of char number.
|
16
|
+
def at(in_srch = nil)
|
17
|
+
if in_srch.is_a?(Integer)
|
18
|
+
return self[in_srch..in_srch]
|
19
|
+
end
|
20
|
+
return nil
|
21
|
+
end
|
22
|
+
|
23
|
+
delegate values_at: :chars
|
24
|
+
delegate delete_at: :chars
|
25
|
+
end
|
26
|
+
end
|
@@ -1,51 +1,51 @@
|
|
1
|
-
# Part of MightyString
|
2
|
-
# by Daniel P. Clark
|
3
|
-
# webmaster@6ftdan.com
|
4
|
-
|
5
|
-
# Del : Delete by index/slice
|
6
|
-
module Del
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
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
|
+
elsif in_srch.is_a?(String) and not in_srch.empty?
|
45
|
+
return self.split(in_srch).join
|
46
|
+
end
|
47
|
+
end
|
48
|
+
return nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Part of MightyString
|
2
|
+
# by Daniel P. Clark
|
3
|
+
# webmaster@6ftdan.com
|
4
|
+
require 'forwardable'
|
5
|
+
|
6
|
+
module Each
|
7
|
+
module String
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
def self.included(base)
|
11
|
+
base.send :extend, Forwardable
|
12
|
+
end
|
13
|
+
|
14
|
+
# Enumerator for String
|
15
|
+
delegate each: :chars
|
16
|
+
delegate each_index: :chars
|
17
|
+
delegate each_with_index: :chars
|
18
|
+
delegate each_entry: :chars
|
19
|
+
delegate each_slice: :chars
|
20
|
+
delegate each_cons: :chars
|
21
|
+
delegate each_with_object: :chars
|
22
|
+
delegate reverse_each: :chars
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Part of MightyString
|
2
|
+
# by Daniel P. Clark
|
3
|
+
# webmaster@6ftdan.com
|
4
|
+
require 'forwardable'
|
5
|
+
|
6
|
+
module Find
|
7
|
+
module String
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
def self.included(base)
|
11
|
+
base.send :extend, Forwardable
|
12
|
+
end
|
13
|
+
|
14
|
+
# Enumerator for String
|
15
|
+
delegate find: :chars
|
16
|
+
delegate find_index: :chars
|
17
|
+
delegate find_all: :chars
|
18
|
+
end
|
19
|
+
end
|