fixed_width_columns 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 59de65defe809f72f7fdebd3aa8a037192357d37
4
+ data.tar.gz: 5cfd3144f551487b70e63344f0a6ee026753658f
5
+ SHA512:
6
+ metadata.gz: 608f58730f707f16a13230d672011e25be937e82f845f020c8033bc439783f859d9ace1a200c23ea5f50533e3c9e88aea4fe8104cee5f7052c7fd57342784df2
7
+ data.tar.gz: d2c677fc35b0d1b5b25f4e4f39c9af5dde17d274197bb59037fa84ddb5609c1234da3abd69b8f7d96fb3be708513bd46e6531d44fa7037b8ae12f2d33bfcc3d2
@@ -0,0 +1,23 @@
1
+ *.bundle
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ .#*
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fixed_width_columns.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Conan Dalton
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.
@@ -0,0 +1,31 @@
1
+ # FixedWidthColumns
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'fixed_width_columns'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fixed_width_columns
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/fixed_width_columns/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fixed_width_columns/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fixed_width_columns"
8
+ spec.version = FixedWidthColumns::VERSION
9
+ spec.authors = ["Conan Dalton"]
10
+ spec.email = ["conan@conandalton.net"]
11
+ spec.summary = %q{Generate fixed-width-column textfiles quickly and easily}
12
+ spec.description = %q{Specify attribute, width, alignment, and padding for each column and call #format and you're good}
13
+ spec.homepage = "https://github.com/conanite/fixed_width_columns"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_dependency 'aduki'
22
+
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'rspec_numbering_formatter'
25
+ spec.add_development_dependency "bundler", "~> 1.7"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
@@ -0,0 +1,18 @@
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
+
11
+ def headers
12
+ columns.map { |col| col.format(col.name.to_s, :padding => ' ') }.join
13
+ end
14
+
15
+ def format thing
16
+ columns.map { |col| col.string_for thing }.join
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ require 'aduki'
2
+
3
+ class FixedWidthColumns
4
+ class FixedWidthAttribute
5
+ include Aduki::Initializer
6
+ attr_writer :align, :padding
7
+ attr_accessor :name, :length
8
+
9
+ def align ; (@align || :right).to_sym ; end
10
+ def padding ; @padding || ' ' ; end
11
+
12
+ def format value, override={ }
13
+ my_length = override[:length] || self.length
14
+ my_align = override[:align] || self.align
15
+ my_padding = override[:padding] || self.padding
16
+
17
+ str = value.to_s[0...length]
18
+ case my_align
19
+ when :left
20
+ str.ljust my_length, my_padding
21
+ when :right
22
+ str.rjust my_length, my_padding
23
+ end
24
+ end
25
+
26
+ def string_for thing
27
+ format thing.send name
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ class FixedWidthColumns
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ require 'fixed_width_columns'
3
+
4
+ describe FixedWidthColumns do
5
+ class FinancialTransaction
6
+ include Aduki::Initializer
7
+ attr_accessor :id, :date, :ref
8
+ attr_writer :debit, :credit
9
+ def debit ; (@debit * 100).to_i; end
10
+ def credit ; (@credit * 100).to_i; end
11
+ end
12
+
13
+ it "should produce text formatted according to the given specification" do
14
+ format_spec = [
15
+ { name: :id , length: 5 },
16
+ { name: :date , length: 14 },
17
+ { name: :ref , length: 24, align: :left },
18
+ { name: :debit , length: 8, padding: '0' },
19
+ { name: :credit , length: 8, padding: '0' },
20
+ ]
21
+
22
+ ft1 = FinancialTransaction.new(id: 1, date: "2003-12-28", ref: "payment thanks", debit: 0.00, credit: 123.45)
23
+ ft2 = FinancialTransaction.new(id: 2, date: "2004-03-12", ref: "invoice 123" , debit: 666.66, credit: 0)
24
+ ft3 = FinancialTransaction.new(id: 3, date: "2005-06-08", ref: "payment thanks", debit: 0.00, credit: 444.44)
25
+ ft4 = FinancialTransaction.new(id: 4, date: "2006-06-21", ref: "credit note" , debit: 0.00, credit: 222.22)
26
+
27
+ formatter = FixedWidthColumns.new(columns: format_spec)
28
+
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"
34
+ end
35
+ end
@@ -0,0 +1,18 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |expectations|
3
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
4
+ end
5
+
6
+ config.mock_with :rspec do |mocks|
7
+ mocks.verify_partial_doubles = true
8
+ end
9
+
10
+ config.filter_run :focus
11
+ config.run_all_when_everything_filtered = true
12
+ if config.files_to_run.one?
13
+ config.default_formatter = 'doc'
14
+ end
15
+
16
+ config.order = :random
17
+ Kernel.srand config.seed
18
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fixed_width_columns
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Conan Dalton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aduki
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec_numbering_formatter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description: 'Specify attribute, width, alignment, and padding for each column and
84
+ call #format and you''re good'
85
+ email:
86
+ - conan@conandalton.net
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - Gemfile
94
+ - MIT-LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - fixed_width_columns.gemspec
98
+ - lib/fixed_width_columns.rb
99
+ - lib/fixed_width_columns/fixed_width_attribute.rb
100
+ - lib/fixed_width_columns/version.rb
101
+ - spec/format_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: https://github.com/conanite/fixed_width_columns
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.2.2
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Generate fixed-width-column textfiles quickly and easily
127
+ test_files:
128
+ - spec/format_spec.rb
129
+ - spec/spec_helper.rb