fixed_width_columns 0.0.1 → 0.0.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 899e47444fbc5159b1801581dc9b538716c594a4
|
4
|
+
data.tar.gz: 847aad4b1447dcb64337d9632b568b533b85ceee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b8786970a9574d76e2936a08cd2a85bad0ae0a9f8dee44e5f5c9c916c540839229c56b9a28ccbd8e371a959a677f69571685542d425d92d7919e0eb75eabdb3
|
7
|
+
data.tar.gz: cefeacfc9eaa9e4efa85c97b56c0736eefe20131c5ba76cfc9d1fda24770fb068a525cf3f948822273d8fd40d011a049f0fdca77f75773905bf49f786be0f1cb
|
@@ -4,17 +4,17 @@ class FixedWidthColumns
|
|
4
4
|
class FixedWidthAttribute
|
5
5
|
include Aduki::Initializer
|
6
6
|
attr_writer :align, :padding
|
7
|
-
attr_accessor :name, :length
|
7
|
+
attr_accessor :name, :length, :text
|
8
8
|
|
9
9
|
def align ; (@align || :right).to_sym ; end
|
10
10
|
def padding ; @padding || ' ' ; end
|
11
11
|
|
12
12
|
def format value, override={ }
|
13
|
-
my_length = override[:length] || self.length
|
13
|
+
my_length = override[:length] || self.length || value.length
|
14
14
|
my_align = override[:align] || self.align
|
15
15
|
my_padding = override[:padding] || self.padding
|
16
16
|
|
17
|
-
str = value.to_s[0...
|
17
|
+
str = value.to_s[0...my_length]
|
18
18
|
case my_align
|
19
19
|
when :left
|
20
20
|
str.ljust my_length, my_padding
|
@@ -24,7 +24,7 @@ class FixedWidthColumns
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def string_for thing
|
27
|
-
format thing.send
|
27
|
+
format(self.text || thing.send(name))
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
data/spec/format_spec.rb
CHANGED
@@ -14,6 +14,7 @@ describe FixedWidthColumns do
|
|
14
14
|
format_spec = [
|
15
15
|
{ name: :id , length: 5 },
|
16
16
|
{ name: :date , length: 14 },
|
17
|
+
{ name: :' ' , text: ' ' },
|
17
18
|
{ name: :ref , length: 24, align: :left },
|
18
19
|
{ name: :debit , length: 8, padding: '0' },
|
19
20
|
{ name: :credit , length: 8, padding: '0' },
|
@@ -26,10 +27,10 @@ describe FixedWidthColumns do
|
|
26
27
|
|
27
28
|
formatter = FixedWidthColumns.new(columns: format_spec)
|
28
29
|
|
29
|
-
expect(formatter.headers). to eq " id
|
30
|
-
expect(formatter.format ft1).to eq " 1 2003-12-
|
31
|
-
expect(formatter.format ft2).to eq " 2 2004-03-
|
32
|
-
expect(formatter.format ft3).to eq " 3 2005-06-
|
33
|
-
expect(formatter.format ft4).to eq " 4 2006-06-
|
30
|
+
expect(formatter.headers). to eq " id date ref debit credit"
|
31
|
+
expect(formatter.format ft1).to eq " 1 2003-12-28 payment thanks 0000000000012345"
|
32
|
+
expect(formatter.format ft2).to eq " 2 2004-03-12 invoice 123 0006666600000000"
|
33
|
+
expect(formatter.format ft3).to eq " 3 2005-06-08 payment thanks 0000000000044444"
|
34
|
+
expect(formatter.format ft4).to eq " 4 2006-06-21 credit note 0000000000022222"
|
34
35
|
end
|
35
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixed_width_columns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Conan Dalton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aduki
|