mightystring 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14ab77de0c0623e196cb95a7d2a49a7a4f0f085d
4
- data.tar.gz: fa10b832c88aa8a17143f557c1d4901abaa96f19
3
+ metadata.gz: f2c6db7592a53f3b0b8da6aad7805996123c093d
4
+ data.tar.gz: 5fc669e5824168df43677c94810d259173b82d17
5
5
  SHA512:
6
- metadata.gz: 76283e2d96e380443c9aad53d9c1a1bfb719e045c5901f1897a9a09ae00625c7fc71e49bbd5bac005ad7eebb32b932dcb068294a86705e936e69edfb1d059241
7
- data.tar.gz: af4651a7787a3d247f1a082555baabe9feb7f40a3fc4fd38f6b60db35a2a86291340338c6a7369b6c19f05de0e5d76c7059d33bb9839a0bee24033877bc271e5
6
+ metadata.gz: e7183e152148b74707088434bb0c4a66be906b40a213d1903155679a41ff41e9d01d2a98024d2e12a4677d6d47585c93e3ed445f019d00a580f6f769dbe009bc
7
+ data.tar.gz: db097d0fe3c382ea1548eb88dde6262781993ae7e2ee27cf369267cd204a1c2d4f81dfb78a9d8f63f2442af8081166492ae57d24cc1908e25bfe9c0a2dda8305
data/.travis.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.2
3
+ - 2.2.4
4
+ - 2.3.0
data/README.md CHANGED
@@ -1,25 +1,119 @@
1
- # MightyString
2
- by Daniel P. Clark
3
-
1
+ ##MightyString
4
2
  [![Gem Version](https://badge.fury.io/rb/mightystring.svg)](http://badge.fury.io/rb/mightystring)
5
3
 
4
+ Powerful methods for your strings.
5
+
6
+ ##Install
7
+
8
+ Add this to your Gemfile and then run `bundle install`.
9
+ ```ruby
10
+ gem 'mightystring', '~> 1.0'
11
+ ```
12
+
13
+ Or you can just install and use it manually.
14
+ ```ruby
15
+ gem install mightystring
16
+ ```
17
+ ##Usage
18
+
19
+ ```ruby
20
+ # String#at
21
+ "abc".at(0)
22
+ # => "a"
23
+ "0123456789".at(-1)
24
+ # => "9"
25
+ "vwq".at(5)
26
+ # => nil
27
+
28
+ # String#del
29
+ "asdfasdf".del(0..2)
30
+ # => "fasdf"
31
+ "asdfasdf".del(1)
32
+ # => "adfasdf"
33
+ "asdfasdf".del([1,3])
34
+ # => "adasdf"
35
+ "asdfasdf".del("a")
36
+ # => "sdfsdf"
37
+
38
+ # String#del!
39
+ str = "asdfasdf"
40
+ str.del!("sd")
41
+ str
42
+ # => "afaf"
43
+ str.del!(1..2)
44
+ str
45
+ # => "af"
46
+
47
+ # String#first
48
+ "asdf".first
49
+ # => "a"
50
+
51
+ # String#last
52
+ "asdf".last
53
+ # => "f"
6
54
 
7
- *Description:* Add Array functionality to Strings and other tools for Strings: Matching, Indexing, Substitution, Deletion, and more.
55
+ # String#pop
56
+ "asdf".pop
57
+ # => "f"
8
58
 
9
- Install: `gem install mightystring`
59
+ # String#push
60
+ "asdf".push("r")
61
+ # => "asdfr"
10
62
 
11
- *Pain points this aims to solve*
12
- * After working with Python, it's obvious Ruby strings are lacking... so lets spiff them up.
13
- * Strings are Arrays... I mean really, think about it. This works toward making Strings function as Arrays.
14
- * Also this provides additional string tools under MightyString... like parsing HTML into text.
63
+ # String#shift
64
+ "asdf".shift
65
+ # => "a"
15
66
 
16
- *My method*
17
- * 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.
67
+ # String#sort
68
+ str = "asdf"
69
+ str.sort
70
+ # => "adfs"
71
+ str
72
+ # => "asdf"
18
73
 
19
- *Some tools to consider here*
74
+ # String#sort!
75
+ str = "asdf"
76
+ str.sort!
77
+ # => "adfs"
78
+ str
79
+ # => "adfs"
80
+
81
+ # String#unshift
82
+ "asdf".unshift("r")
83
+ # => "rasdf"
84
+
85
+ # String#values_at
86
+ "asdfasdfasdf".values_at(0,5,-1)
87
+ # => ["a", "s", "f"]
88
+
89
+ # String#index_all
90
+ "012324507654301243".index_all( "0" )
91
+ # => [0,7,13]
92
+ "the apple is the best fruit in the world".index_all( "the" )
93
+ # => [0, 13, 31]
94
+ "asdfasdfasdf".index_all( /sd/ )
95
+ # => [1,5,9]
96
+
97
+ # String#sift
98
+ "qwertyuiop".sift( "aeiou" )
99
+ # => "euio"
100
+ "qa2ws3ed4rf5tg6yh7uj8ik9ol".sift( Range.new( "0", "9" ) )
101
+ # => "23456789"
102
+
103
+ # String#head
104
+ "asdf".head
105
+ # => "a"
106
+ "asdf".head(3)
107
+ # => "asd"
108
+
109
+ # String#tail
110
+ "asdf".tail
111
+ # => "sdf"
112
+ "asdf".tail(3)
113
+ # => "f"
114
+ ```
115
+
116
+ ##Extras
20
117
  * MightyString::HTML.text 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.
21
118
 
22
- *Advanced detail*
23
- * Look at the test/mightystring_test.rb for case usages of each feature.
24
-
25
- > NOTES: Implementing the flatten and join methods on String breaks functionality within Rails and Rubygems so this has been avoided.
119
+ Look at the test/mightystring_test.rb for case usages of each feature.
@@ -27,6 +27,10 @@ module MightyString
27
27
  replace del(indexes)
28
28
  end
29
29
 
30
+ def head offset = 1
31
+ self[0...offset]
32
+ end
33
+
30
34
  def index_all matcher
31
35
  arr_indexes = []
32
36
  srch_index = rindex(matcher)
@@ -75,6 +79,10 @@ module MightyString
75
79
  replace sort
76
80
  end
77
81
 
82
+ def tail offset = 1
83
+ self[offset..-1]
84
+ end
85
+
78
86
  def unshift str
79
87
  replace str.+(self)
80
88
  end
@@ -1,3 +1,3 @@
1
1
  module MightyString
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -2,11 +2,11 @@ require 'minitest_helper'
2
2
 
3
3
  describe MightyString do
4
4
  it "String#at returns character at position" do
5
- _("abc".at(0)).must_equal "a"
5
+ _("abc".at(0)).must_equal "a"
6
6
  _("0123456789".at(-1)).must_equal "9"
7
7
  _("vwq".at(5)).must_be_nil
8
8
  _("vwq".at(-5)).must_be_nil
9
- end
9
+ end
10
10
 
11
11
  it "String#del deletes characters at positions" do
12
12
  _("asdfasdf".del(0..2)).must_equal "fasdf"
@@ -19,7 +19,7 @@ describe MightyString do
19
19
  str.del! (1..2)
20
20
  _(str).must_equal "af"
21
21
  end
22
-
22
+
23
23
  it "Can get the first and last character" do
24
24
  _("asdf".first).must_equal "a"
25
25
  _("asdf".last).must_equal "f"
@@ -37,6 +37,16 @@ describe MightyString do
37
37
  _("asdf".shift).must_equal "a"
38
38
  end
39
39
 
40
+ it "String#head" do
41
+ _("asdf".head).must_equal "a"
42
+ _("asdf".head(3)).must_equal "asd"
43
+ end
44
+
45
+ it "String#tail" do
46
+ _("asdf".tail).must_equal "sdf"
47
+ _("asdf".tail(3)).must_equal "f"
48
+ end
49
+
40
50
  it "sorts" do
41
51
  str = "asdf"
42
52
  _(str.sort).must_equal "adfs"
@@ -53,31 +63,33 @@ describe MightyString do
53
63
  _("asdfasdfasdf".values_at(0,5,-1)).must_equal ["a", "s", "f"]
54
64
  end
55
65
 
56
- it "String#index_all returns all indexes of given string" do
66
+ it "String#index_all returns all indexes of given string" do
57
67
  _("012324507654301243".index_all("0")).must_equal [0,7,13]
58
68
  _("the apple is the best fruit in the world".index_all("the")).must_equal [0, 13, 31]
59
69
  _("asdfasdfasdf".index_all(/sd/)).must_equal [1,5,9]
60
- end
61
-
62
- it "sifts out bad characters" do
70
+ _("asdfasdfasdf".index_all('a')).must_equal [0,4,8]
71
+ _("asdfasdfasdf".index_all('f')).must_equal [3,7,11]
72
+ end
73
+
74
+ it "sifts out bad characters" do
63
75
  _("qa2ws3ed4rf5tg6yh7uj8ik9ol".sift(Range.new( "0", "9" ))).must_equal "23456789"
64
-
65
- custRange = (Range.new('a','z').to_a + Range.new('A','Z').to_a + [" "]).flatten
76
+
77
+ custRange = (Range.new('a','z').to_a + Range.new('A','Z').to_a + [" "]).flatten
66
78
  _("<html><body> Content </body></html>".sift(custRange)).must_equal "htmlbody Content bodyhtml"
67
- end
68
-
69
- def test_strip_first_seq
70
- MightyString::HTML.strip_first_seq("APPLES n APPLES ARE Yummy!","APPLES",{"APPLES" => "COWS"}).must_equal "COWS n APPLES ARE Yummy!"
71
- MightyString::HTML.strip_first_seq("Cows Cows and more Cows!","Cows", {"Cows" => "Winner"}).must_equal "Winner Cows and more Cows!"
72
- MightyString::HTML.strip_first_seq("&nbsp; ---- &nbsp; APPLES &nbps;", "&nbsp;" ).must_equal " ---- &nbsp; APPLES &nbps;"
73
- MightyString::HTML.strip_first_seq("&trade; ---- &trade; TradeMark &trade;", "&trade;" ).must_equal "(TM) ---- &trade; TradeMark &trade;"
74
- end
75
-
76
- def test_strip_html
77
- MightyString::HTML.text("<html>").must_equal ""
78
- MightyString::HTML.text("<table><tr><td>Piped sides.</td></tr></table>", :mappings => {"td" => ' | '}).must_equal " | Piped sides. | "
79
- MightyString::HTML.text("Hello<br>World!").must_equal "Hello\nWorld!"
80
- MightyString::HTML.text("<p>&quot;Quoted&quot; Copyright &copy; TradeMark &trade;</p>").must_equal "'Quoted' Copyright (c) TradeMark (TM)"
81
- end
79
+ end
80
+
81
+ it "strips/substitues custom sequences" do
82
+ _(MightyString::HTML.strip_first_seq("APPLES n APPLES ARE Yummy!","APPLES",{"APPLES" => "COWS"})).must_equal "COWS n APPLES ARE Yummy!"
83
+ _(MightyString::HTML.strip_first_seq("Cows Cows and more Cows!","Cows", {"Cows" => "Winner"})).must_equal "Winner Cows and more Cows!"
84
+ _(MightyString::HTML.strip_first_seq("&nbsp; ---- &nbsp; APPLES &nbps;", "&nbsp;" )).must_equal " ---- &nbsp; APPLES &nbps;"
85
+ _(MightyString::HTML.strip_first_seq("&trade; ---- &trade; TradeMark &trade;", "&trade;" )).must_equal "(TM) ---- &trade; TradeMark &trade;"
86
+ end
87
+
88
+ it "strips HTML and substitues new mappings" do
89
+ _(MightyString::HTML.text("<html>")).must_equal ""
90
+ _(MightyString::HTML.text("<table><tr><td>Piped sides.</td></tr></table>", :mappings => {"td" => ' | '})).must_equal " | Piped sides. | "
91
+ _(MightyString::HTML.text("Hello<br>World!")).must_equal "Hello\nWorld!"
92
+ _(MightyString::HTML.text("<p>&quot;Quoted&quot; Copyright &copy; TradeMark &trade;</p>")).must_equal "'Quoted' Copyright (c) TradeMark (TM)"
93
+ end
82
94
  end
83
95
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mightystring
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel P. Clark / 6ftDan(TM)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-15 00:00:00.000000000 Z
11
+ date: 2016-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler