verse 0.1.0 → 0.1.1
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/lib/verse.rb +10 -1
- data/lib/verse/alignment.rb +15 -4
- data/lib/verse/truncation.rb +2 -2
- data/lib/verse/version.rb +1 -1
- data/lib/verse/wrapping.rb +3 -1
- data/spec/unit/align_spec.rb +10 -0
- data/spec/unit/alignment/align_spec.rb +9 -0
- data/verse.gemspec +2 -2
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc1a8ae257dbf4375ade97c14a82a3c503e6cc77
|
4
|
+
data.tar.gz: 72b99cd80248381793dffdf17da244262102eeed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 997f15ac54e59b69109e053efeffcbab9fcfb15f2b4b56fa8f64b1e5c08199594ec0c73ac71c78d42764b73eb2aabf7f82f646ac789cbadfb21e9d7690ec9804
|
7
|
+
data.tar.gz: ffd2478585b1284f9182df2db36aae47371a6d3f8aabaa33a52cd20098859a1b1e3b68a40add61b4802289135f9b6e0cf17ad0122af8d6a1c1594bdb967668d1
|
data/lib/verse.rb
CHANGED
@@ -11,6 +11,15 @@ module Verse
|
|
11
11
|
NEWLINE = "\n".freeze
|
12
12
|
TAB = "\n".freeze
|
13
13
|
|
14
|
+
# Align a text to a given direction with the width
|
15
|
+
#
|
16
|
+
# @see Verse::Alignment#align
|
17
|
+
#
|
18
|
+
# @api public
|
19
|
+
def self.align(text, width, direction, options = {})
|
20
|
+
Alignment.align(text, width, direction, options)
|
21
|
+
end
|
22
|
+
|
14
23
|
# Truncate a text at a given length
|
15
24
|
#
|
16
25
|
# @see Verse::Truncation#truncate
|
@@ -26,6 +35,6 @@ module Verse
|
|
26
35
|
#
|
27
36
|
# @api public
|
28
37
|
def self.wrap(text, wrap_at, options = {})
|
29
|
-
Wrapping.wrap(text, wrap_at, options
|
38
|
+
Wrapping.wrap(text, wrap_at, options)
|
30
39
|
end
|
31
40
|
end # Verse
|
data/lib/verse/alignment.rb
CHANGED
@@ -44,6 +44,15 @@ module Verse
|
|
44
44
|
align(width, :right, options)
|
45
45
|
end
|
46
46
|
|
47
|
+
# Align a text to a given direction with the width
|
48
|
+
#
|
49
|
+
# @see Verse::Alignment#align
|
50
|
+
#
|
51
|
+
# @api public
|
52
|
+
def self.align(text, width, direction, options)
|
53
|
+
new(text, options).align(width, direction, options)
|
54
|
+
end
|
55
|
+
|
47
56
|
# Aligns text within the width.
|
48
57
|
#
|
49
58
|
# If the text is greater than the width then unmodified
|
@@ -63,18 +72,20 @@ module Verse
|
|
63
72
|
#
|
64
73
|
# @api public
|
65
74
|
def align(width, direction = :left, options = {})
|
75
|
+
return text unless width
|
76
|
+
|
66
77
|
filler = options.fetch(:fill) { fill }
|
67
78
|
method = convert_to_method(direction)
|
68
79
|
process_lines { |line| line.send(method, width, filler) }
|
69
80
|
end
|
70
81
|
|
71
|
-
|
82
|
+
protected
|
72
83
|
|
73
84
|
# @api private
|
74
85
|
def convert_to_method(direction)
|
75
|
-
case direction
|
76
|
-
when :left
|
77
|
-
when :right
|
86
|
+
case direction.to_sym
|
87
|
+
when :left then :ljust
|
88
|
+
when :right then :rjust
|
78
89
|
when :center then :center
|
79
90
|
else
|
80
91
|
fail ArgumentError, "Unknown alignment `#{direction}`."
|
data/lib/verse/truncation.rb
CHANGED
@@ -34,7 +34,7 @@ module Verse
|
|
34
34
|
#
|
35
35
|
# @api public
|
36
36
|
def self.truncate(text, truncate_at, options = {})
|
37
|
-
new(text).truncate(truncate_at, options)
|
37
|
+
new(text, options).truncate(truncate_at, options)
|
38
38
|
end
|
39
39
|
|
40
40
|
# Truncate a text at a given length (defualts to 30)
|
@@ -71,7 +71,7 @@ module Verse
|
|
71
71
|
chars[0, stop || length_without_trailing].join + trail
|
72
72
|
end
|
73
73
|
|
74
|
-
|
74
|
+
protected
|
75
75
|
|
76
76
|
attr_reader :text
|
77
77
|
end # Truncation
|
data/lib/verse/version.rb
CHANGED
data/lib/verse/wrapping.rb
CHANGED
@@ -31,7 +31,7 @@ module Verse
|
|
31
31
|
#
|
32
32
|
# @api public
|
33
33
|
def self.wrap(text, wrap_at, options = {})
|
34
|
-
new(text).wrap(wrap_at, options)
|
34
|
+
new(text, options).wrap(wrap_at, options)
|
35
35
|
end
|
36
36
|
|
37
37
|
# Wrap a text into lines no longer than wrap_at length.
|
@@ -118,6 +118,8 @@ module Verse
|
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
+
protected
|
122
|
+
|
121
123
|
attr_reader :text
|
122
124
|
end # Wrapping
|
123
125
|
end # Verse
|
@@ -3,6 +3,15 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe Verse::Alignment, '.align' do
|
6
|
+
|
7
|
+
it "doesn't align unrecognized direction" do
|
8
|
+
text = "the madness of men"
|
9
|
+
alignment = Verse::Alignment.new(text)
|
10
|
+
expect {
|
11
|
+
alignment.align(22, :unknown)
|
12
|
+
}.to raise_error(ArgumentError, /Unknown alignment/)
|
13
|
+
end
|
14
|
+
|
6
15
|
it "centers line" do
|
7
16
|
text = "the madness of men"
|
8
17
|
alignment = Verse::Alignment.new(text)
|
data/verse.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Verse::VERSION
|
9
9
|
spec.authors = ["Piotr Murach"]
|
10
10
|
spec.email = [""]
|
11
|
-
spec.summary = %q{}
|
12
|
-
spec.description = %q{}
|
11
|
+
spec.summary = %q{Text transformations such as truncation, wrapping, aligning, indentation and grouping of words.}
|
12
|
+
spec.description = %q{Text transformations such as truncation, wrapping, aligning, indentation and grouping of words.}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: verse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,7 +24,8 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
|
-
description:
|
27
|
+
description: Text transformations such as truncation, wrapping, aligning, indentation
|
28
|
+
and grouping of words.
|
28
29
|
email:
|
29
30
|
- ''
|
30
31
|
executables: []
|
@@ -46,6 +47,7 @@ files:
|
|
46
47
|
- lib/verse/version.rb
|
47
48
|
- lib/verse/wrapping.rb
|
48
49
|
- spec/spec_helper.rb
|
50
|
+
- spec/unit/align_spec.rb
|
49
51
|
- spec/unit/alignment/align_spec.rb
|
50
52
|
- spec/unit/alignment/left_spec.rb
|
51
53
|
- spec/unit/alignment/right_spec.rb
|
@@ -83,9 +85,11 @@ rubyforge_project:
|
|
83
85
|
rubygems_version: 2.0.3
|
84
86
|
signing_key:
|
85
87
|
specification_version: 4
|
86
|
-
summary:
|
88
|
+
summary: Text transformations such as truncation, wrapping, aligning, indentation
|
89
|
+
and grouping of words.
|
87
90
|
test_files:
|
88
91
|
- spec/spec_helper.rb
|
92
|
+
- spec/unit/align_spec.rb
|
89
93
|
- spec/unit/alignment/align_spec.rb
|
90
94
|
- spec/unit/alignment/left_spec.rb
|
91
95
|
- spec/unit/alignment/right_spec.rb
|