fixed_width_columns 0.0.5 → 0.0.7
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 +5 -5
- data/lib/fixed_width_columns/config.rb +17 -0
- data/lib/fixed_width_columns/fixed_width_attribute.rb +1 -1
- data/lib/fixed_width_columns/formatter.rb +15 -0
- data/lib/fixed_width_columns/library.rb +24 -0
- data/lib/fixed_width_columns/preprocessor.rb +15 -0
- data/lib/fixed_width_columns/version.rb +2 -2
- data/lib/fixed_width_columns.rb +12 -14
- data/spec/format_spec.rb +2 -2
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e97c0f82dea52721c1c5a24912ab08a668df05a219fbe0880c029f512ae63078
|
4
|
+
data.tar.gz: d11c2994ce17acaacb4c35ca54a88df5fda4d6c857bbbe434a65ce4cf88b6444
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b21f31685f5791033be3b89d33c2b94f0a54f4ba28ecf583d80a34abedf233b668bbbe2e9a1caa56672b9f417e437cd3bf6ecc81d04de0e887d04c5d186b87d7
|
7
|
+
data.tar.gz: '08bf1dba401d0cd1bdf02b774f9ed9e0aac7adc513e3c8d13d81f2975ed88614e9a09b6ebd50d1a582be4cea0a7ba862f72b516272f37a0cdb700b97ccf571a1'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'aduki'
|
2
|
+
|
3
|
+
module FixedWidthColumns
|
4
|
+
class Config < Aduki::Initializable
|
5
|
+
attr_accessor :name, :target, :label
|
6
|
+
aduki formatter: FixedWidthColumns::Formatter
|
7
|
+
aduki preprocessors: FixedWidthColumns::PreProcessor
|
8
|
+
|
9
|
+
def to_text items, header=nil
|
10
|
+
pre_process(items).inject(headers? header) { |ll, i| ll << formatter.format(i) }.join "\n"
|
11
|
+
end
|
12
|
+
|
13
|
+
@@export_configs = { }
|
14
|
+
def headers? header ; header ? [formatter.headers] : [] ; end
|
15
|
+
def pre_process items ; (preprocessors || []).inject(items) { |list, pp| pp.apply list } ; end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'aduki'
|
2
|
+
|
3
|
+
module FixedWidthColumns
|
4
|
+
class Formatter < Aduki::Initializable
|
5
|
+
aduki columns: FixedWidthColumns::FixedWidthAttribute
|
6
|
+
|
7
|
+
def headers
|
8
|
+
columns.map { |col| col.format(col.name.to_s, :padding => ' ') }.join
|
9
|
+
end
|
10
|
+
|
11
|
+
def format thing
|
12
|
+
columns.map { |col| col.string_for thing }.join
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'aduki'
|
2
|
+
|
3
|
+
module FixedWidthColumns
|
4
|
+
class Library < Aduki::Initializable
|
5
|
+
attr_accessor :config_root
|
6
|
+
aduki_initialize :export_configs, Hash
|
7
|
+
|
8
|
+
def export_config_for klass, name
|
9
|
+
export_configs_for(klass).detect { |cfg| cfg.name == name }
|
10
|
+
end
|
11
|
+
|
12
|
+
def export_configs_for klass
|
13
|
+
klass = klass.class_name if klass.is_a? Class
|
14
|
+
export_configs[klass] ||= load_export_configs_for klass
|
15
|
+
end
|
16
|
+
|
17
|
+
def load_export_configs_for klass
|
18
|
+
path = File.join config_root, "#{klass}.yml"
|
19
|
+
return [] unless File.exist?(path)
|
20
|
+
cfgs = YAML::load File.read path
|
21
|
+
cfgs.map { |k,v| FixedWidthColumns::Config.new v.merge("target" => klass, "name" => k) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'aduki'
|
2
|
+
|
3
|
+
module FixedWidthColumns
|
4
|
+
class PreProcessor < Aduki::Initializable
|
5
|
+
attr_accessor :filter, :transform, :library
|
6
|
+
|
7
|
+
def filter_sym ; (@filter || "true").to_sym ; end
|
8
|
+
def do_filter items ; items.select &(FixedWidthColumns::FILTERS[filter_sym]) ; end
|
9
|
+
def maybe_transform items ; @transform ? do_transform(items) : items ; end
|
10
|
+
def do_transform items ; FixedWidthColumns::TRANSFORMS[@transform.to_sym].call items ; end
|
11
|
+
def apply items ; maybe_transform do_filter items ; end
|
12
|
+
def to_s ; "filter:#{@filter};transform:#{@transform}" ; end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0.
|
1
|
+
module FixedWidthColumns
|
2
|
+
VERSION = "0.0.7"
|
3
3
|
end
|
data/lib/fixed_width_columns.rb
CHANGED
@@ -1,18 +1,16 @@
|
|
1
1
|
require 'aduki'
|
2
|
-
require "fixed_width_columns/version"
|
3
|
-
require "fixed_width_columns/fixed_width_attribute"
|
4
|
-
|
5
|
-
class FixedWidthColumns
|
6
|
-
include Aduki::Initializer
|
7
|
-
include Aduki::Initializer
|
8
|
-
attr_accessor :columns
|
9
|
-
aduki columns: FixedWidthAttribute
|
10
2
|
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
module FixedWidthColumns
|
4
|
+
FILTERS = { }
|
5
|
+
TRANSFORMS = { }
|
14
6
|
|
15
|
-
def
|
16
|
-
|
17
|
-
end
|
7
|
+
def self.transformer name, proc ; TRANSFORMS[name] = proc ; end
|
8
|
+
def self.filter name, proc ; FILTERS[name] = proc ; end
|
18
9
|
end
|
10
|
+
|
11
|
+
require "fixed_width_columns/version"
|
12
|
+
require "fixed_width_columns/library"
|
13
|
+
require "fixed_width_columns/fixed_width_attribute"
|
14
|
+
require "fixed_width_columns/formatter"
|
15
|
+
require "fixed_width_columns/preprocessor"
|
16
|
+
require "fixed_width_columns/config"
|
data/spec/format_spec.rb
CHANGED
@@ -35,7 +35,7 @@ describe FixedWidthColumns do
|
|
35
35
|
ft3 = FinancialTransaction.new(id: 3, account: bank , date: "to be determined", ref: "payment thanks", debit: 0.00, credit: 444.44)
|
36
36
|
ft4 = FinancialTransaction.new(id: 4, account: customer, date: dp("2006-06-21") , ref: "credit note" , debit: 0.00, credit: 222.22)
|
37
37
|
|
38
|
-
formatter = FixedWidthColumns.new(columns: format_spec)
|
38
|
+
formatter = FixedWidthColumns::Formatter.new(columns: format_spec)
|
39
39
|
|
40
40
|
expect(formatter.headers). to eq " id date ref debit credit account.name"
|
41
41
|
expect(formatter.format ft1).to eq " 1 28122003 payment thanks 0000000000012345 Bank"
|
@@ -60,7 +60,7 @@ describe FixedWidthColumns do
|
|
60
60
|
ft3 = FinancialTransaction.new(id: 3, account: bank , date: "to be determined", ref: "payment thanks", debit: 0.00, credit: 444.44)
|
61
61
|
ft4 = FinancialTransaction.new(id: 4, account: customer, date: dp("2006-06-21") , ref: "credit note" , debit: 0.00, credit: 222.22)
|
62
62
|
|
63
|
-
formatter = FixedWidthColumns.new(columns: format_spec)
|
63
|
+
formatter = FixedWidthColumns::Formatter.new(columns: format_spec)
|
64
64
|
|
65
65
|
expect(formatter.headers). to eq "thingthing.dat thing.de account.name"
|
66
66
|
expect(formatter.format({ thing: ft1, account: bank})).to eq " 1 28122003 00000000 Bank"
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Conan Dalton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aduki
|
@@ -96,7 +96,11 @@ files:
|
|
96
96
|
- Rakefile
|
97
97
|
- fixed_width_columns.gemspec
|
98
98
|
- lib/fixed_width_columns.rb
|
99
|
+
- lib/fixed_width_columns/config.rb
|
99
100
|
- lib/fixed_width_columns/fixed_width_attribute.rb
|
101
|
+
- lib/fixed_width_columns/formatter.rb
|
102
|
+
- lib/fixed_width_columns/library.rb
|
103
|
+
- lib/fixed_width_columns/preprocessor.rb
|
100
104
|
- lib/fixed_width_columns/version.rb
|
101
105
|
- spec/format_spec.rb
|
102
106
|
- spec/spec_helper.rb
|
@@ -119,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
123
|
- !ruby/object:Gem::Version
|
120
124
|
version: '0'
|
121
125
|
requirements: []
|
122
|
-
|
123
|
-
rubygems_version: 2.2.2
|
126
|
+
rubygems_version: 3.0.3.1
|
124
127
|
signing_key:
|
125
128
|
specification_version: 4
|
126
129
|
summary: Generate fixed-width-column textfiles quickly and easily
|