mightystring 0.2.0 → 1.0.0

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: c1dc9af7333c929b1b42ace68f82c7b090f0ead9
4
- data.tar.gz: 30145612c2b45d9bce6d734212dd0f3468f579c8
3
+ metadata.gz: 14ab77de0c0623e196cb95a7d2a49a7a4f0f085d
4
+ data.tar.gz: fa10b832c88aa8a17143f557c1d4901abaa96f19
5
5
  SHA512:
6
- metadata.gz: ba8d2e06a9af2b34cd54b469f7609dae61e9bcbab4e479f6d943598efbb4d07f6e6d89d6d333c2c3b7d04168dd2b113a33c4f1390aa6bff32049db8f71719bc0
7
- data.tar.gz: 0918a55c46ef10645a6950e3399dbc1c0d0e0c55f25c1a03260e4ab394062e6730cc141e943fb5baec81ffd75ca62ae056827404c071c8b0dbd36f8f973bf9e5
6
+ metadata.gz: 76283e2d96e380443c9aad53d9c1a1bfb719e045c5901f1897a9a09ae00625c7fc71e49bbd5bac005ad7eebb32b932dcb068294a86705e936e69edfb1d059241
7
+ data.tar.gz: af4651a7787a3d247f1a082555baabe9feb7f40a3fc4fd38f6b60db35a2a86291340338c6a7369b6c19f05de0e5d76c7059d33bb9839a0bee24033877bc271e5
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ *.swp
3
+ /.idea/
4
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in MightyString.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2012-2016 Daniel P. Clark & 6ft Dan(TM)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -2,37 +2,24 @@
2
2
  by Daniel P. Clark
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/mightystring.svg)](http://badge.fury.io/rb/mightystring)
5
- [![Epic Winning](https://img.shields.io/badge/Epic-Winning-brightgreen.svg?style=flat)](https://rubygems.org/gems/mightystring)
6
-
7
- [![Ruby Version Support](https://img.shields.io/badge/Ruby%20Version%20Support-1.8.7-red.svg?style=flat)](https://www.ruby-lang.org)
8
5
 
9
6
 
10
7
  *Description:* Add Array functionality to Strings and other tools for Strings: Matching, Indexing, Substitution, Deletion, and more.
11
8
 
12
9
  Install: `gem install mightystring`
13
10
 
14
- *Pain points this solves.*
11
+ *Pain points this aims to solve*
15
12
  * After working with Python, it's obvious Ruby strings are lacking... so lets spiff them up.
16
13
  * Strings are Arrays... I mean really, think about it. This works toward making Strings function as Arrays.
17
14
  * Also this provides additional string tools under MightyString... like parsing HTML into text.
18
15
 
19
- *My method.*
16
+ *My method*
20
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.
21
18
 
22
- *Some tools to consider here.*
19
+ *Some tools to consider here*
23
20
  * 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.
24
21
 
25
- *Advanced detail.*
26
- * Look at the test/test_ms.rb for case usages of each feature.
27
-
28
- > As a general rule I've avoided regex for this library. But due to regex's nature of design I will use it for
29
- parsing string data within **MightyString::HTML** . I plan to keep parsing syntax as the only exception for using regex in this library.
30
-
31
- Follow this project and contribute via github http://www.github.com/danielpclark/mightystring
32
- <br />
33
- <br />
34
- # Goal for 0.3.0
35
- *Have Array and String interchangable. Same errors, same results.*
22
+ *Advanced detail*
23
+ * Look at the test/mightystring_test.rb for case usages of each feature.
36
24
 
37
- > NOTES: Implementing the flatten and join methods on String breaks functionality within Rails and Rubygems. Future
38
- additions will be separated into the MightyString module itself. Although a brilliant idea may indeed resolve this.
25
+ > NOTES: Implementing the flatten and join methods on String breaks functionality within Rails and Rubygems so this has been avoided.
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ #require 'rdoc/task'
10
+ #
11
+ #RDoc::Task.new(:rdoc) do |rdoc|
12
+ # rdoc.rdoc_dir = 'rdoc'
13
+ # rdoc.title = 'MightyString'
14
+ # rdoc.options << '--line-numbers'
15
+ # rdoc.rdoc_files.include('README.rdoc')
16
+ # rdoc.rdoc_files.include('lib/**/*.rb')
17
+ #end
18
+
19
+ Bundler::GemHelper.install_tasks
20
+
21
+ require 'rake/testtask'
22
+
23
+ Rake::TestTask.new(:test) do |t|
24
+ t.libs << 'lib'
25
+ t.libs << 'test'
26
+ t.pattern = 'test/**/*_test.rb'
27
+ t.verbose = false
28
+ end
29
+
30
+
31
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "MightyString"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,72 @@
1
+ module MightyString
2
+ module HTML
3
+ def self.text(htmlstr, options = {})
4
+ options[:mappings] = default_options[:mappings].
5
+ merge(options.delete(:mappings)) if options.has_key?(:mappings)
6
+ options = default_options.merge(options)
7
+ options[:tag_markers].each { |g|
8
+ sh_endpoints = htmlstr.index_all(g[1])
9
+ if sh_endpoints.nil?
10
+ break
11
+ end
12
+ sh_end = htmlstr.rindex(g[1])
13
+ sh_start = htmlstr.rindex(g[0])
14
+ while !!sh_end and !!sh_start do
15
+ if sh_end > sh_start
16
+ sh_seq = htmlstr[sh_start,sh_end - sh_start + 1]
17
+ until sh_seq.count(g[1]) == 1 do # until we've selected only the inner block
18
+ sh_end = htmlstr[0,sh_end-1].rindex(g[1])
19
+ sh_seq = htmlstr[sh_start,sh_end - sh_start + 1]
20
+ end
21
+ if not (options[:math_by_space] and not html_math_exceptions(htmlstr[sh_start,sh_end - sh_start + 1]) == 0)
22
+ htmlstr = strip_first_seq( htmlstr, htmlstr[sh_start,sh_end - sh_start + 1], options[:mappings])
23
+ else
24
+ sh_end = sh_end - 1
25
+ end
26
+ else
27
+ sh_start = sh_start - 1
28
+ end
29
+ sh_end = htmlstr[0..sh_end].rindex(g[1])
30
+ sh_start = htmlstr[0..sh_start].rindex(g[0])
31
+ end
32
+ }
33
+ return htmlstr
34
+ end
35
+
36
+ def self.html_math_exceptions(in_str = "")
37
+ if in_str["< "] or in_str["& "]
38
+ return 1 # Execption found at beginning
39
+ 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
40
+ return 2 # Exception found for both
41
+ else
42
+ return 0
43
+ end
44
+
45
+ end
46
+
47
+ # strip sequence out ( master string, sequence to remove, any characters to swap inplace this for that )
48
+ def self.strip_first_seq( mstr = "", mseq = "", cmpchar = default_options[:mappings] )
49
+ if not cmpchar.empty? and cmpchar.keys.any? {|mkey| mseq.downcase[mkey.downcase] } # keys exist and one of the keys match
50
+ cmpchar.each_key { |mkey|
51
+ if mseq.downcase[mkey.downcase]
52
+ mstr = mstr[0,mstr.index(mseq)] + cmpchar[mkey] + mstr[(mstr.index(mseq)+mseq.length)..-1]
53
+ end
54
+ }
55
+ elsif mstr.index(mseq)
56
+ mstr = mstr[0,mstr.index(mseq)] + mstr[(mstr.index(mseq)+mseq.length)..-1]
57
+ end
58
+ return mstr
59
+ end
60
+
61
+ def self.default_options
62
+ {
63
+ :tag_markers => [["<",">"],["&",";"]],
64
+ :mappings => {
65
+ "&quot;"=>"'","br"=>"\n","&#39;" => "'", "&nbsp;" => " ", "&trade;" => "(TM)", "&copy;" => "(c)"
66
+ },
67
+ :math_by_space => false # FIXME certain (long) A href tags slip through
68
+ }
69
+ end
70
+
71
+ end # module Strip_HTML
72
+ end # MightyString
@@ -0,0 +1,82 @@
1
+ require'forwardable'
2
+
3
+ module MightyString
4
+ module String
5
+ def self.included(base)
6
+ base.class_eval {
7
+ alias_method :at, :[]
8
+
9
+ extend Forwardable
10
+ def_delegators :chars, :first, :last, :values_at
11
+ }
12
+ end
13
+
14
+ def del indexes
15
+ case indexes
16
+ when String then split(indexes).join
17
+ else
18
+ each_char.with_index.
19
+ reduce([]) {|arr,(c,i)|
20
+ arr << c unless Array(indexes).include?(i)
21
+ arr
22
+ }.join
23
+ end
24
+ end
25
+
26
+ def del! indexes
27
+ replace del(indexes)
28
+ end
29
+
30
+ def index_all matcher
31
+ arr_indexes = []
32
+ srch_index = rindex(matcher)
33
+ while srch_index do
34
+ tmpStr = self[0..srch_index-1]
35
+ arr_indexes << srch_index
36
+ srch_index = srch_index.zero? ? nil : tmpStr.rindex(matcher)
37
+ end
38
+ arr_indexes.reverse
39
+ end
40
+
41
+ def pop
42
+ chr = self[-1]
43
+ replace chop
44
+ chr
45
+ end
46
+
47
+ def push str
48
+ replace self.+(str)
49
+ end
50
+
51
+ def shift
52
+ chr = self[0]
53
+ replace self[1..-1]
54
+ chr
55
+ end
56
+
57
+ def sift chars_to_keep
58
+ chars_to_keep = case chars_to_keep
59
+ when String then chars_to_keep.chars
60
+ when Array then chars_to_keep
61
+ when Range then chars_to_keep.to_a
62
+ else
63
+ raise TypeError, "Invalid parameter"
64
+ end
65
+ chars.keep_if {|chr|
66
+ chars_to_keep.include? chr
67
+ }.join
68
+ end
69
+
70
+ def sort
71
+ chars.sort.join
72
+ end
73
+
74
+ def sort!
75
+ replace sort
76
+ end
77
+
78
+ def unshift str
79
+ replace str.+(self)
80
+ end
81
+ end
82
+ end
@@ -1,3 +1,3 @@
1
1
  module MightyString
2
- VERSION = "0.2.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/mightystring.rb CHANGED
@@ -1,41 +1,7 @@
1
- require 'mightystring/string_at'
2
- require 'mightystring/string_del'
3
- # require 'mightystring/string_each'
4
- require 'mightystring/string_fetch'
5
- # require 'mightystring/string_find'
6
- require 'mightystring/string_first'
7
- require 'mightystring/string_index_all'
8
- # require 'mightystring/string_join'
9
- require 'mightystring/string_last'
10
- require 'mightystring/string_map'
11
- require 'mightystring/string_match_pci'
12
- require 'mightystring/string_pop'
13
- require 'mightystring/string_push'
14
- require 'mightystring/string_shift'
15
- require 'mightystring/string_sort'
16
- require 'mightystring/string_strip_byac'
17
- require 'mightystring/string_unshift'
18
- require 'mightystring/strip_html'
1
+ require 'mightystring/string'
2
+ require 'mightystring/html'
19
3
  require 'mightystring/version'
20
- # require 'mightystring/string_method_missing'
21
4
 
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
5
+ module MightyString
6
+ ::String.include String
7
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "mightystring/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'mightystring'
8
+ s.version = MightyString::VERSION
9
+ s.license = 'MIT'
10
+ s.summary = "Strings (are) Arrays with Matching, Indexing, Substitution, Deletion, and more."
11
+ s.description = "Array functionality in Strings as well as Matching, Indexing, Substitution, Deletion, and more."
12
+ s.authors = ["Daniel P. Clark / 6ftDan(TM)"]
13
+ s.email = ["6ftdan@gmail.com"]
14
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ s.homepage = 'http://www.github.com/danielpclark/mightystring'
16
+ s.platform = 'ruby'
17
+ s.bindir = 'bin'
18
+ s.executables = 'ms-striphtml'
19
+ s.require_paths = ['lib']
20
+ s.test_files = ["test/mightystring_test.rb"]
21
+ s.required_ruby_version = '>= 1.8'
22
+
23
+ s.add_development_dependency "bundler", "~> 1.11"
24
+ s.add_development_dependency "rake", "~> 10.5"
25
+ s.add_development_dependency "minitest", "~> 5.8"
26
+ s.add_development_dependency "minitest-reporters", "~> 1.1"
27
+ s.add_development_dependency "color_pound_spec_reporter", "~> 0.0.5"
28
+ end
@@ -0,0 +1,83 @@
1
+ require 'minitest_helper'
2
+
3
+ describe MightyString do
4
+ it "String#at returns character at position" do
5
+ _("abc".at(0)).must_equal "a"
6
+ _("0123456789".at(-1)).must_equal "9"
7
+ _("vwq".at(5)).must_be_nil
8
+ _("vwq".at(-5)).must_be_nil
9
+ end
10
+
11
+ it "String#del deletes characters at positions" do
12
+ _("asdfasdf".del(0..2)).must_equal "fasdf"
13
+ _("asdfasdf".del(1)).must_equal "adfasdf"
14
+ _("asdfasdf".del([1,3])).must_equal "adasdf"
15
+ _("asdfasdf".del("a")).must_equal "sdfsdf"
16
+ str = "asdfasdf"
17
+ str.del! "sd"
18
+ _(str).must_equal "afaf"
19
+ str.del! (1..2)
20
+ _(str).must_equal "af"
21
+ end
22
+
23
+ it "Can get the first and last character" do
24
+ _("asdf".first).must_equal "a"
25
+ _("asdf".last).must_equal "f"
26
+ end
27
+
28
+ it "String#pop pops it like it's hot" do
29
+ _("asdf".pop).must_equal "f"
30
+ end
31
+
32
+ it "String#push pushes like Sisyphus" do
33
+ _("asdf".push("r")).must_equal "asdfr"
34
+ end
35
+
36
+ it "String#shift" do
37
+ _("asdf".shift).must_equal "a"
38
+ end
39
+
40
+ it "sorts" do
41
+ str = "asdf"
42
+ _(str.sort).must_equal "adfs"
43
+ _(str).must_equal "asdf"
44
+ str.sort!
45
+ _(str).must_equal "adfs"
46
+ end
47
+
48
+ it "String#unshift" do
49
+ _("asdf".unshift("r")).must_equal "rasdf"
50
+ end
51
+
52
+ it "String#values_at will show values at individual locations" do
53
+ _("asdfasdfasdf".values_at(0,5,-1)).must_equal ["a", "s", "f"]
54
+ end
55
+
56
+ it "String#index_all returns all indexes of given string" do
57
+ _("012324507654301243".index_all("0")).must_equal [0,7,13]
58
+ _("the apple is the best fruit in the world".index_all("the")).must_equal [0, 13, 31]
59
+ _("asdfasdfasdf".index_all(/sd/)).must_equal [1,5,9]
60
+ end
61
+
62
+ it "sifts out bad characters" do
63
+ _("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
66
+ _("<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
82
+ end
83
+
metadata CHANGED
@@ -1,51 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mightystring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
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: 2015-01-16 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2016-01-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-reporters
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: color_pound_spec_reporter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.0.5
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.5
13
83
  description: Array functionality in Strings as well as Matching, Indexing, Substitution,
14
84
  Deletion, and more.
15
- email: webmaster@6ftdan.com
85
+ email:
86
+ - 6ftdan@gmail.com
16
87
  executables:
17
88
  - ms-striphtml
18
89
  extensions: []
19
90
  extra_rdoc_files: []
20
91
  files:
21
- - LICENSE
92
+ - ".gitignore"
93
+ - ".travis.yml"
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - LICENSE.txt
22
97
  - README.md
98
+ - Rakefile
99
+ - bin/console
23
100
  - bin/ms-striphtml
101
+ - bin/setup
24
102
  - lib/mightystring.rb
25
- - lib/mightystring/string_at.rb
26
- - lib/mightystring/string_del.rb
27
- - lib/mightystring/string_each.rb
28
- - lib/mightystring/string_fetch.rb
29
- - lib/mightystring/string_find.rb
30
- - lib/mightystring/string_first.rb
31
- - lib/mightystring/string_index_all.rb
32
- - lib/mightystring/string_join.rb
33
- - lib/mightystring/string_last.rb
34
- - lib/mightystring/string_map.rb
35
- - lib/mightystring/string_match_pci.rb
36
- - lib/mightystring/string_method_missing.rb
37
- - lib/mightystring/string_pop.rb
38
- - lib/mightystring/string_push.rb
39
- - lib/mightystring/string_shift.rb
40
- - lib/mightystring/string_sort.rb
41
- - lib/mightystring/string_strip_byac.rb
42
- - lib/mightystring/string_unshift.rb
43
- - lib/mightystring/strip_html.rb
103
+ - lib/mightystring/html.rb
104
+ - lib/mightystring/string.rb
44
105
  - lib/mightystring/version.rb
45
- - test/test_ms.rb
106
+ - mightystring.gemspec
107
+ - test/mightystring_test.rb
46
108
  homepage: http://www.github.com/danielpclark/mightystring
47
109
  licenses:
48
- - The MIT License (MIT)
110
+ - MIT
49
111
  metadata: {}
50
112
  post_install_message:
51
113
  rdoc_options: []
@@ -63,10 +125,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
125
  version: '0'
64
126
  requirements: []
65
127
  rubyforge_project:
66
- rubygems_version: 2.4.5
128
+ rubygems_version: 2.5.1
67
129
  signing_key:
68
130
  specification_version: 4
69
131
  summary: Strings (are) Arrays with Matching, Indexing, Substitution, Deletion, and
70
132
  more.
71
133
  test_files:
72
- - test/test_ms.rb
134
+ - test/mightystring_test.rb
data/LICENSE DELETED
@@ -1,10 +0,0 @@
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
-
@@ -1,25 +0,0 @@
1
- # Part of MightyString
2
- # by Daniel P. Clark
3
- # webmaster@6ftdan.com
4
-
5
- # At
6
- module At
7
- module String
8
-
9
- # At : Returns string instead of char number.
10
- def at(in_srch = nil)
11
- if in_srch.is_a?(Integer)
12
- return self[in_srch..in_srch]
13
- end
14
- return nil
15
- end
16
-
17
- def values_at(*args)
18
- self.chars.values_at(*args).join
19
- end
20
-
21
- def delete_at(arg)
22
- self.replace self[0...arg] + self[arg+1..-1]
23
- end
24
- end
25
- end
@@ -1,51 +0,0 @@
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
@@ -1,23 +0,0 @@
1
- # Won't be using forwardable
2
- #
3
- # require 'forwardable'
4
- #
5
- # module Each
6
- # module String
7
- # extend Forwardable
8
- #
9
- # def self.included(base)
10
- # base.send :extend, Forwardable
11
- # end
12
- #
13
- # # Enumerator for String
14
- # delegate :each => :chars
15
- # delegate :each_index => :chars
16
- # delegate :each_with_index => :chars
17
- # delegate :each_entry => :chars
18
- # delegate :each_slice => :chars
19
- # delegate :each_cons => :chars
20
- # delegate :each_with_object => :chars
21
- # delegate :reverse_each => :chars
22
- # end
23
- # end
@@ -1,13 +0,0 @@
1
- # Part of MightyString
2
- # by Daniel P. Clark
3
- # webmaster@6ftdan.com
4
-
5
-
6
- module Fetch
7
- module String
8
- # Fetch position in String
9
- def fetch(x)
10
- return self[x]
11
- end
12
- end
13
- end
@@ -1,18 +0,0 @@
1
- # Won't be using forwardable
2
- #
3
- # require 'forwardable'
4
- #
5
- # module Find
6
- # module String
7
- # extend Forwardable
8
- #
9
- # def self.included(base)
10
- # base.send :extend, Forwardable
11
- # end
12
- #
13
- # # Enumerator for String
14
- # delegate :find => :chars
15
- # delegate :find_index => :chars
16
- # delegate :find_all => :chars
17
- # end
18
- # end
@@ -1,13 +0,0 @@
1
- # Part of MightyString
2
- # by Daniel P. Clark
3
- # webmaster@6ftdan.com
4
-
5
-
6
- module First
7
- module String
8
- # First character in String
9
- def first
10
- return self[0]
11
- end
12
- end
13
- end
@@ -1,27 +0,0 @@
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
@@ -1,10 +0,0 @@
1
- # Breaks Rails as is with cookies feature
2
- #
3
- # module Join
4
- # module String
5
- # # Returns String
6
- # def join
7
- # return self
8
- # end
9
- # end
10
- # end
@@ -1,13 +0,0 @@
1
- # Part of MightyString
2
- # by Daniel P. Clark
3
- # webmaster@6ftdan.com
4
-
5
-
6
- module Last
7
- module String
8
- # Last character in String
9
- def last
10
- return self[-1]
11
- end
12
- end
13
- end
@@ -1,33 +0,0 @@
1
- # Part of MightyString
2
- # by Daniel P. Clark
3
- # webmaster@6ftdan.com
4
- #require 'forwardable'
5
-
6
- module Map
7
- module String
8
-
9
- def map(*args, &block)
10
- if (!args.compact.empty? || !block.nil?)
11
- self.chars.map(*args,&block).join
12
- else
13
- self.chars.map(*args,&block)
14
- end
15
- end
16
-
17
- def map!(*args, &block)
18
- if (!args.compact.empty? || !block.nil?)
19
- self.replace self.chars.map(*args,&block).join
20
- else
21
- self.chars.map(*args,&block)
22
- end
23
- end
24
-
25
- def flat_map(*args, &block)
26
- if (!args.compact.empty? || !block.nil?)
27
- self.chars.flat_map(*args,&block).join
28
- else
29
- self.chars.flat_map(*args,&block)
30
- end
31
- end
32
- end
33
- end
@@ -1,16 +0,0 @@
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.downcase[in_srch.downcase]
12
- end
13
- return false
14
- end
15
- end
16
- end
@@ -1,40 +0,0 @@
1
- # Part of MightyString
2
- # by Daniel P. Clark
3
- # webmaster@6ftdan.com
4
-
5
- #module MethodMissing
6
- # module String
7
- #
8
- # def method_missing(meth,*args, &block)
9
- # if self.chars.respond_to? meth
10
- # self.chars.send meth, *args, &block
11
- # else
12
- # super
13
- # end
14
- # end
15
- #
16
- # def respond_to?(meth)
17
- # if self.chars.respond_to? meth
18
- # true
19
- # else
20
- # super
21
- # end
22
- # end
23
- #
24
- # end
25
- #end
26
-
27
- #class Array
28
- # To fix a bug that our method_missing creates
29
- # we need to set a MAXIMUM for FLATTEN
30
- # alias_method :_old_flatten, :flatten
31
- # alias_method :_old_flatten!, :flatten!
32
- #
33
- # def flatten(level = 42)
34
- # _old_flatten(level)
35
- # end
36
- #
37
- # def flatten!(level = 42)
38
- # _old_flatten!(level)
39
- # end
40
- #end
@@ -1,15 +0,0 @@
1
- # Part of MightyString
2
- # by Daniel P. Clark
3
- # webmaster@6ftdan.com
4
-
5
-
6
- module Pop
7
- module String
8
- # Pop character from String
9
- def pop
10
- x = self[-1]
11
- self.replace self.chop
12
- return x
13
- end
14
- end
15
- end
@@ -1,13 +0,0 @@
1
- # Part of MightyString
2
- # by Daniel P. Clark
3
- # webmaster@6ftdan.com
4
-
5
-
6
- module Push
7
- module String
8
- # Push character in String
9
- def push(x)
10
- self << x.to_s
11
- end
12
- end
13
- end
@@ -1,15 +0,0 @@
1
- # Part of MightyString
2
- # by Daniel P. Clark
3
- # webmaster@6ftdan.com
4
-
5
-
6
- module Shift
7
- module String
8
- # Shift from start of String
9
- def shift
10
- x = self[0]
11
- self.replace self[1..-1]
12
- return x
13
- end
14
- end
15
- end
@@ -1,17 +0,0 @@
1
- # Part of MightyString
2
- # by Daniel P. Clark
3
- # webmaster@6ftdan.com
4
-
5
-
6
- module Sort
7
- module String
8
- # Return sorted String
9
- def sort
10
- return self.split("").sort.join
11
- end
12
- # Sort String
13
- def sort!
14
- self.replace self.split("").sort.join
15
- end
16
- end
17
- end
@@ -1,28 +0,0 @@
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 Strip_byAC
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
@@ -1,13 +0,0 @@
1
- # Part of MightyString
2
- # by Daniel P. Clark
3
- # webmaster@6ftdan.com
4
-
5
-
6
- module UnShift
7
- module String
8
- # Unshift from start of String
9
- def unshift(x)
10
- self.replace x.to_s + self
11
- end
12
- end
13
- end
@@ -1,118 +0,0 @@
1
- # Mighty String - HTML to text parser
2
- #
3
- # TODO *FIXME* A rare href exception gets by, as well as some comment cases, only if math_by_space is enabled. 0.1 11-27-2012 "Release Version"
4
- # TODO FEATURE: Split all lines in document and make sure only one blank new-line is permitted.
5
- #
6
- # Ver 0.1 11-27-2012 "Release Version"
7
- # - Modularized and Gemified
8
- # - Fixed mathmatical exceptions. Code is completely functional with test case.
9
- #
10
- # Ver Pre_0.3.0 8-7-2012
11
- # - Added String modules for a healthy and useful String library
12
- # - Finished mathmatical and generic & exceptions
13
- #
14
- # Ver Pre_0.2.1
15
- # - Fixed indexing problem when only 1 of two cases where 'paired'. Such as '<' and not '>'. It died previously on nil.
16
- # - Added test case
17
- #
18
- # Ver Pre_0.2
19
- # - Added command line html file processing
20
- # - Added case insensitivity for HTML snippets
21
- #
22
- # Ver Pre_0.1
23
- # - HTML tag stripper with ASCII output
24
-
25
- require 'string_match_pci' unless defined? Match_PCI
26
- require 'string_index_all' unless defined? Index_All
27
-
28
- # END REQUIRE #
29
- class String
30
- include Index_All::String
31
- include Match_PCI::String
32
- end
33
-
34
- module MightyString
35
- module HTML
36
- def self.text(htmlstr, options = {})
37
- options[:mappings] = default_options[:mappings].
38
- merge(options.delete(:mappings)) if options.has_key?(:mappings)
39
- options = default_options.merge(options)
40
- options[:tag_markers].each { |g|
41
- sh_endpoints = htmlstr.index_all(g[1])
42
- if sh_endpoints.nil?
43
- break
44
- end
45
- sh_end = htmlstr.rindex(g[1])
46
- sh_start = htmlstr.rindex(g[0])
47
- while !!sh_end and !!sh_start do
48
- if sh_end > sh_start
49
- sh_seq = htmlstr[sh_start,sh_end - sh_start + 1]
50
- until sh_seq.count(g[1]) == 1 do # until we've selected only the inner block
51
- sh_end = htmlstr[0,sh_end-1].rindex(g[1])
52
- sh_seq = htmlstr[sh_start,sh_end - sh_start + 1]
53
- end
54
- if not (options[:math_by_space] and not html_math_exceptions(htmlstr[sh_start,sh_end - sh_start + 1]) == 0)
55
- htmlstr = strip_first_seq( htmlstr, htmlstr[sh_start,sh_end - sh_start + 1], options[:mappings])
56
- else
57
- sh_end = sh_end - 1
58
- end
59
- else
60
- sh_start = sh_start - 1
61
- end
62
- sh_end = htmlstr[0..sh_end].rindex(g[1])
63
- sh_start = htmlstr[0..sh_start].rindex(g[0])
64
- end
65
- }
66
- return htmlstr
67
- end
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 = default_options[:mappings] )
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
-
95
- # <b>DEPRECATED:</b> Please use <tt>MightyString::HTML.text</tt> instead.
96
- # Pick tags/blocks of string to remove (ex: "&", ";" like in "&quot;" can become "" or "'" if rules set))
97
- def self.strip_html( htmlstr = "", xarg = default_options[:tag_markers] ) # xarg start, end
98
- warn "#{Kernel.caller.first} [DEPRECATED] `MightyString::HTML.strip_html` is depreciated. Please use MightyString::HTML.text instead."
99
- text(htmlstr, :tag_markers => xarg)
100
- end
101
-
102
- def self.default_options
103
- {
104
- :tag_markers => [["<",">"],["&",";"]],
105
- :mappings => {
106
- "&quot;"=>"'","br"=>"\n","&#39;" => "'", "&nbsp;" => " ", "&trade;" => "(TM)", "&copy;" => "(c)"
107
- },
108
- :math_by_space => false,
109
- :drop_styles => true, # TODO Add this feature
110
- :drop_scripts => true, # TODO Add this feature
111
- :drop_iframes => false, # TODO Add this feature
112
- :permitted_blank_line_rows => 1, # TODO Add this feature
113
- :images_to_alt_text => false # TODO Add this feature
114
- }
115
- end
116
-
117
- end # module Strip_HTML
118
- end # MightyString
data/test/test_ms.rb DELETED
@@ -1,53 +0,0 @@
1
- require 'test/unit'
2
- $: << 'lib/'
3
- require 'mightystring'
4
-
5
- class TestMightyString < Test::Unit::TestCase
6
- def test_at
7
- assert "abc".at(0) == "a"
8
- assert "0123456789".at(-1) == "9"
9
- end
10
-
11
- def test_del
12
- assert "abc".del(1) == "ac"
13
- assert "0123456789".del(0..2) == "3456789"
14
- assert "iudsfbv\nui4adv\nvw7revg".del("\n") == "iudsfbvui4advvw7revg"
15
- end
16
-
17
- # def test_each
18
- # assert "12345".each.all?{|i| i.to_i < 10}
19
- # end
20
-
21
- def test_index_all
22
- assert "012324507654301243".index_all 0 == [0,7,13]
23
- assert "the apple is the best fruit in the world".index_all "the" == [0, 13, 31]
24
- end
25
-
26
- def test_match_pci
27
- assert "<TD>".match_pci("td")
28
- assert "<TD>".match_pci("><") == false
29
- assert "Principle".match_pci("rINCi")
30
- end
31
-
32
- def test_strip_byac
33
- assert "qa2ws3ed4rf5tg6yh7uj8ik9ol".strip_byac( Range.new( "0", "9" ).to_a ) == "23456789"
34
-
35
- custRange = (Range.new('a','z').to_a + Range.new('A','Z').to_a + [" "]).flatten
36
- assert "<html><body> Content </body></html>".strip_byac(custRange) == "htmlbody Content bodyhtml"
37
- end
38
-
39
- def test_strip_first_seq
40
- assert MightyString::HTML.strip_first_seq("APPLES n APPLES ARE Yummy!","APPLES",{"APPLES" => "COWS"}) == "COWS n APPLES ARE Yummy!"
41
- assert MightyString::HTML.strip_first_seq("Cows Cows and more Cows!","Cows", {"Cows" => "Winner"}) == "Winner Cows and more Cows!"
42
- assert MightyString::HTML.strip_first_seq("&nbsp; ---- &nbsp; APPLES &nbps;", "&nbsp;" ) == " ---- &nbsp; APPLES &nbps;"
43
- assert MightyString::HTML.strip_first_seq("&trade; ---- &trade; TradeMark &trade;", "&trade;" ) == "(TM) ---- &trade; TradeMark &trade;"
44
- end
45
-
46
- def test_strip_html
47
- assert MightyString::HTML.text("<html>") == ""
48
- assert MightyString::HTML.text("<table><tr><td>Piped sides.</td></tr></table>", :mappings => {"td" => ' | '}) == " | Piped sides. | "
49
- assert MightyString::HTML.text("Hello<br>World!") == "Hello\nWorld!"
50
- assert MightyString::HTML.text("<p>&quot;Quoted&quot; Copyright &copy; TradeMark &trade;</p>") == "'Quoted' Copyright (c) TradeMark (TM)"
51
- end
52
- end
53
-