wrapify 0.1.0 → 0.1.2
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.
- checksums.yaml +4 -4
- data/.gitignore +8 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/wrapify.rb +73 -0
- data/lib/wrapify/version.rb +3 -0
- data/tasks/rspec.rake +4 -0
- data/wrapify-0.1.0.gem +0 -0
- data/wrapify-0.1.1.gem +0 -0
- data/wrapify.gemspec +36 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc4d00eec7c721d08079dfd04d01775ac8ed1795ea64e82d476da366ba6b397e
|
4
|
+
data.tar.gz: 8e470a50652486291b6f3bdbb21faccb81c7b125dfc6664f1ae4ba6992826473
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a7cd4d5fecba7fcfce741727634369ba2320ce0c44fbccfc092fc8a45d20e59a86b70203fae9a16471959b40a0da6289f7252ebf0518f587050417b65f8783e
|
7
|
+
data.tar.gz: 6f786dbf119c90378022c07afcf94d91da0602ee73b4ae68959f05ace1e61c2e88063a344abb205f64cd806d5f03a55955b448cce54a34f8f89d6d2dcfa2edcb
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
wrapify (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.4.2)
|
11
|
+
rspec (3.7.0)
|
12
|
+
rspec-core (~> 3.7.0)
|
13
|
+
rspec-expectations (~> 3.7.0)
|
14
|
+
rspec-mocks (~> 3.7.0)
|
15
|
+
rspec-core (3.7.1)
|
16
|
+
rspec-support (~> 3.7.0)
|
17
|
+
rspec-expectations (3.7.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.7.0)
|
20
|
+
rspec-mocks (3.7.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.7.0)
|
23
|
+
rspec-support (3.7.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.16)
|
30
|
+
rake (~> 10.0)
|
31
|
+
rspec (~> 3.7, >= 3.7.0)
|
32
|
+
wrapify!
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Frank Germano
|
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
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Wrapify
|
2
|
+
|
3
|
+
Wrapify is a gem that extends the string class to add a method wrapify(wraplimit).
|
4
|
+
This gem supports wrapping text to a specified boundary, e.g. 20. The string can include multiple newlines.
|
5
|
+
|
6
|
+
Algorithm: Convert all runs of white space (spaces, tabs, new lines, carriage returns) to single spaces.
|
7
|
+
Define the runs of characters between the spaces as "words". Add words to a line until they no longer
|
8
|
+
fit (hitting the word wrap limit). Once a line is complete, add it to the final result, with a closing new line. Continue adding lines to the result until there is no more to process. The result can be a multiline string.
|
9
|
+
|
10
|
+
If a word is longer than the wraplimit, it is added to its own "long" line; this line will extend past the wordwrap limit. This is by design. One could add an option to the method to force wrap the line to avoid lines. This alternative has not been implemented.
|
11
|
+
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'wrapify'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install wrapify
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
For a given string, mystring, invoke the string method, wrap_to_string, with a wraplimit.
|
32
|
+
|
33
|
+
mystring.wrap_to_string(20)
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fgermanojr/wrapify.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). More generally, do whatever you want with it.
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
5
|
+
t.pattern = Dir.glob('spec/**/*_spec.rb')
|
6
|
+
t.rspec_opts = '--format documentation'
|
7
|
+
# t.rspec_opts << ' more options'
|
8
|
+
# t.rcov = true # ADD GEM LATER
|
9
|
+
end
|
10
|
+
task :default => :spec
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "wrapify"
|
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(__FILE__)
|
data/bin/setup
ADDED
data/lib/wrapify.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require "wrapify/version"
|
2
|
+
|
3
|
+
class String
|
4
|
+
|
5
|
+
# Wrap string to given wraplimit.
|
6
|
+
#
|
7
|
+
# @param decimal wraplimit
|
8
|
+
# @return [String]
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
|
12
|
+
# doc1 = <<-DOC1HERE
|
13
|
+
# line 1 contains a lot of stuff
|
14
|
+
# line 2 contains even more, which we will wrap to a fixed short
|
15
|
+
# line 3 boundry if we are lucky. Who knows what will really happen.
|
16
|
+
# line 4
|
17
|
+
# DOC1HERE
|
18
|
+
|
19
|
+
# doc1.wrap_to_limit(20) === doc1_wrapped
|
20
|
+
|
21
|
+
# doc1_ wrapped = <<-RESULT
|
22
|
+
# line 1 contains a
|
23
|
+
# lot of stuff line
|
24
|
+
# 2 contains even
|
25
|
+
# more, which we
|
26
|
+
# will wrap to a
|
27
|
+
# fixed short line 3
|
28
|
+
# boundry if we are
|
29
|
+
# lucky. Who knows
|
30
|
+
# what will really
|
31
|
+
# happen. line 4
|
32
|
+
# RESULT
|
33
|
+
|
34
|
+
def wrap_to_limit(wrap_limit)
|
35
|
+
str = self.gsub(/\s+/, ' ') # convert runs of white space to single space
|
36
|
+
String.wrap_process(str, wrap_limit)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def self.wrap_process(str, wrap_limit)
|
42
|
+
# Wrap units into line not to exceed wrap_limit of line
|
43
|
+
# In case where next_up is longer than wrap we include with overlength.
|
44
|
+
# Could add option, :force, 'xxxyy\n'.wrap_to_limit(4) = 'xxxy\ny\n'
|
45
|
+
# Thnik about.
|
46
|
+
|
47
|
+
str_array = str.split(' ')
|
48
|
+
run_index = 0
|
49
|
+
result = ''
|
50
|
+
line = ''
|
51
|
+
|
52
|
+
until str_array.empty? do
|
53
|
+
next_up = str_array.shift
|
54
|
+
# puts "next_up=#{next_up}"
|
55
|
+
if (line.length + next_up.length + 1 < wrap_limit)
|
56
|
+
# got room add it in
|
57
|
+
line += next_up + ' '
|
58
|
+
run_index += 1
|
59
|
+
else
|
60
|
+
line = next_up if line.empty? # edge case, test 4
|
61
|
+
# start new line
|
62
|
+
result += line + "\n" unless str_array.empty? # edge case, test 2
|
63
|
+
# puts 'reset'
|
64
|
+
line = next_up + ' '
|
65
|
+
run_index += 1
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
result += line.strip + "\n" if line.length > 0 # Don't lose what is left
|
70
|
+
result
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
data/tasks/rspec.rake
ADDED
data/wrapify-0.1.0.gem
ADDED
Binary file
|
data/wrapify-0.1.1.gem
ADDED
Binary file
|
data/wrapify.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "wrapify/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "wrapify"
|
8
|
+
spec.version = Wrapify::VERSION
|
9
|
+
spec.authors = ["Frank Germano"]
|
10
|
+
spec.email = ["fgermano@earthlink.net"]
|
11
|
+
|
12
|
+
spec.summary = "Wrap lines at given char limit"
|
13
|
+
spec.description = "Wrap lines at given char limit"
|
14
|
+
spec.homepage = "https://github.com/fgermanojr/wrapify.git"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
# "public gem pushes."
|
24
|
+
# end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.7", ">= 3.7.0"
|
36
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wrapify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Germano
|
@@ -64,8 +64,23 @@ email:
|
|
64
64
|
executables: []
|
65
65
|
extensions: []
|
66
66
|
extra_rdoc_files: []
|
67
|
-
files:
|
68
|
-
|
67
|
+
files:
|
68
|
+
- ".gitignore"
|
69
|
+
- ".travis.yml"
|
70
|
+
- Gemfile
|
71
|
+
- Gemfile.lock
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- bin/console
|
76
|
+
- bin/setup
|
77
|
+
- lib/wrapify.rb
|
78
|
+
- lib/wrapify/version.rb
|
79
|
+
- tasks/rspec.rake
|
80
|
+
- wrapify-0.1.0.gem
|
81
|
+
- wrapify-0.1.1.gem
|
82
|
+
- wrapify.gemspec
|
83
|
+
homepage: https://github.com/fgermanojr/wrapify.git
|
69
84
|
licenses:
|
70
85
|
- MIT
|
71
86
|
metadata: {}
|