fixed_width_columns 0.0.1 → 0.0.2

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: 59de65defe809f72f7fdebd3aa8a037192357d37
4
- data.tar.gz: 5cfd3144f551487b70e63344f0a6ee026753658f
3
+ metadata.gz: 899e47444fbc5159b1801581dc9b538716c594a4
4
+ data.tar.gz: 847aad4b1447dcb64337d9632b568b533b85ceee
5
5
  SHA512:
6
- metadata.gz: 608f58730f707f16a13230d672011e25be937e82f845f020c8033bc439783f859d9ace1a200c23ea5f50533e3c9e88aea4fe8104cee5f7052c7fd57342784df2
7
- data.tar.gz: d2c677fc35b0d1b5b25f4e4f39c9af5dde17d274197bb59037fa84ddb5609c1234da3abd69b8f7d96fb3be708513bd46e6531d44fa7037b8ae12f2d33bfcc3d2
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...length]
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 name
27
+ format(self.text || thing.send(name))
28
28
  end
29
29
  end
30
30
  end
@@ -1,3 +1,3 @@
1
1
  class FixedWidthColumns
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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 dateref debit credit"
30
- expect(formatter.format ft1).to eq " 1 2003-12-28payment thanks 0000000000012345"
31
- expect(formatter.format ft2).to eq " 2 2004-03-12invoice 123 0006666600000000"
32
- expect(formatter.format ft3).to eq " 3 2005-06-08payment thanks 0000000000044444"
33
- expect(formatter.format ft4).to eq " 4 2006-06-21credit note 0000000000022222"
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.1
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-27 00:00:00.000000000 Z
11
+ date: 2015-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aduki