justify 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +1 -0
- data/justify.gemspec +23 -0
- data/lib/justify.rb +26 -0
- data/lib/justify/version.rb +3 -0
- metadata +102 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9a17cf2789829cb6248e9075f0881b5abc418435
|
4
|
+
data.tar.gz: ccd03699ad1b66986606280cf8e3f96660c514fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6088783a62fe564eb33e116cc153f8c922c99a056f6d9e58787dab08bfea4e245b1d34c86011066f081e36c0027ad3cc3bc1321b699360fc78c09b4852817114
|
7
|
+
data.tar.gz: 96115d02b069929d76e4e64a297b92300d94abe44d8105453475ab43d1ff28bb8e5247812bf332fd8f1ca33f12e5c01eec03dbd09af51e7fb6f78ee6b5925fa0
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Paolo Perego
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Justify
|
2
|
+
|
3
|
+
justify helps in formatting a very long line of text breaking it up for a given width
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'justify'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install justify
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Using justify it's easy.
|
22
|
+
|
23
|
+
```
|
24
|
+
require 'justify'
|
25
|
+
|
26
|
+
|
27
|
+
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat".justify
|
28
|
+
|
29
|
+
# Lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore
|
30
|
+
# et dolore magna aliqua Ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut
|
31
|
+
# aliquip ex ea commodo consequat
|
32
|
+
|
33
|
+
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat".justify(20)
|
34
|
+
|
35
|
+
# Lorem ipsum dolor sit amet
|
36
|
+
# consectetur adipisicing
|
37
|
+
# elit sed do eiusmod tempor
|
38
|
+
# incididunt ut labore et
|
39
|
+
# dolore magna aliqua Ut enim
|
40
|
+
# ad minim veniam quis nostrudexercitation ullamco laborisnisi ut aliquip ex ea commodoconsequat
|
41
|
+
```
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/justify.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'justify/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "justify"
|
8
|
+
spec.version = Justify::VERSION
|
9
|
+
spec.authors = ["Paolo Perego"]
|
10
|
+
spec.email = ["thesp0nge@gmail.com"]
|
11
|
+
spec.description = %q{justify is a gem helping in break very long string in a fixed width text}
|
12
|
+
spec.summary = %q{justify is a gem helping in break very long string in a fixed width text}
|
13
|
+
spec.homepage = "http://armoredcode.com/how-to-wrap-a-long-text-to-fit-your-terminal-width-in-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/justify.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "justify/version"
|
2
|
+
|
3
|
+
class String
|
4
|
+
def justify(len = 80)
|
5
|
+
unless self.length < len
|
6
|
+
|
7
|
+
words = self.gsub("\n", " ").scan(/\w+/)
|
8
|
+
actual_len = 0
|
9
|
+
output = ""
|
10
|
+
words.each do |w|
|
11
|
+
output += w
|
12
|
+
actual_len += w.length
|
13
|
+
if actual_len >= len
|
14
|
+
output += "\n"
|
15
|
+
actual_len = 0
|
16
|
+
else
|
17
|
+
output += " "
|
18
|
+
end
|
19
|
+
end
|
20
|
+
return output
|
21
|
+
else
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: justify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paolo Perego
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MQ4wDAYDVQQDDAVwYW9s
|
14
|
+
bzEYMBYGCgmSJomT8ixkARkWCGNvZGVzYWtlMRMwEQYKCZImiZPyLGQBGRYDY29t
|
15
|
+
MB4XDTE0MDEyNzE3MjUwMVoXDTE1MDEyNzE3MjUwMVowPzEOMAwGA1UEAwwFcGFv
|
16
|
+
bG8xGDAWBgoJkiaJk/IsZAEZFghjb2Rlc2FrZTETMBEGCgmSJomT8ixkARkWA2Nv
|
17
|
+
bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBA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 Z
|
34
|
+
dependencies:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: bundler
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.3'
|
42
|
+
type: :development
|
43
|
+
prerelease: false
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.3'
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rake
|
51
|
+
requirement: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
description: justify is a gem helping in break very long string in a fixed width text
|
64
|
+
email:
|
65
|
+
- thesp0nge@gmail.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- justify.gemspec
|
76
|
+
- lib/justify.rb
|
77
|
+
- lib/justify/version.rb
|
78
|
+
homepage: http://armoredcode.com/how-to-wrap-a-long-text-to-fit-your-terminal-width-in-ruby
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.1.11
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: justify is a gem helping in break very long string in a fixed width text
|
102
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|