fixy 0.0.2 → 0.0.3

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: 920d1f790730e2a1fab764c52a27a6296c1864b0
4
- data.tar.gz: 2d41058beac14b76f575244fce378390ccdb153e
3
+ metadata.gz: 9262fa93a8633148f73159bacbbcb4d21ed4b408
4
+ data.tar.gz: 8994b5cd70ce533762cab617358e21f69cf12547
5
5
  SHA512:
6
- metadata.gz: 3f88596d4ae34bad598b91b943dd7a57015374a1069ed4a06be59084c7409b0e52378a12557eebeaf1a2702c98c6fff38f73f9f7d397c637a7b16e508478d173
7
- data.tar.gz: 612e1d75d45282c9a252e6ebadaf3d1c3a6e914e401d9975e13a786f3b21454f7c28d2d5b1080e94376ac725a8e0caebe2958512ebc0f6026f07625e3575364d
6
+ metadata.gz: ff5b8c0e48810b780fa12ef0eaa2c64c4ca4c7a3a36790808cc31b09d260149e83158eaab624231311e368842b4192d550b1ba176be6fb7e87141faaedaf14d4
7
+ data.tar.gz: 17ed2f4d5c446805a342181736bcf4e6c1f672b20e8b16b3f184d1c66f6fc4bde028e85ce7e4e439251162ef7931c5f907908799d31fc49c5054061f34a363d6
data/.gitignore CHANGED
@@ -16,4 +16,6 @@ spec/reports
16
16
  test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
- /pmip
19
+ /pmip
20
+ .ruby-version
21
+
@@ -1,3 +1,8 @@
1
+ ## v0.0.3
2
+
3
+ * Allow passing block to field to define field_value
4
+ * Update handling of multi-byte characters
5
+
1
6
  ## v0.0.2
2
7
 
3
8
  * Fixed typos in README
@@ -6,4 +11,4 @@
6
11
 
7
12
  ## v0.0.1
8
13
 
9
- * Initial release
14
+ * Initial release
@@ -9,15 +9,22 @@ module Fixy
9
9
  # left-justified and filled with spaces.
10
10
  #
11
11
 
12
- def format_alphanumeric(input, bytes)
13
- input_string = String.new(input.to_s)
14
- truncated_bytesize = [input_string.bytesize, bytes].min
15
- if truncated_bytesize < bytes
16
- input_string << " " * (bytes - truncated_bytesize)
17
- input_string
12
+ def format_alphanumeric(input, byte_width)
13
+ result = ''
14
+
15
+ if input.bytesize <= byte_width
16
+ result = input.dup
18
17
  else
19
- input_string.byteslice(0..(truncated_bytesize - 1))
18
+ input.each_char do |char|
19
+ if result.bytesize + char.bytesize <= byte_width
20
+ result << char
21
+ else
22
+ break
23
+ end
24
+ end
20
25
  end
26
+
27
+ result << " " * (byte_width - result.bytesize)
21
28
  end
22
29
  end
23
30
  end
@@ -32,6 +32,8 @@ module Fixy
32
32
 
33
33
  # We're good to go :)
34
34
  @record_fields[range_from] = { name: name, from: range_from, to: range_to, size: size, type: type}
35
+
36
+ field_value(name, Proc.new) if block_given?
35
37
  end
36
38
 
37
39
  # Convenience method for creating field methods
@@ -1,3 +1,3 @@
1
1
  module Fixy
2
- VERSION = "0.0.2"
2
+ VERSION = '0.0.3'
3
3
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'spec_helper'
2
3
 
3
4
  describe 'Defining a Record' do
@@ -56,24 +57,47 @@ end
56
57
 
57
58
  describe 'Generating a Record' do
58
59
  context 'when properly defined' do
59
- it 'should generate fixed width record' do
60
- class PersonRecordE < Fixy::Record
61
- include Fixy::Formatter::Alphanumeric
60
+ class PersonRecordE < Fixy::Record
61
+ include Fixy::Formatter::Alphanumeric
62
62
 
63
- set_record_length 20
63
+ set_record_length 20
64
64
 
65
- field :first_name, 10, '1-10' , :alphanumeric
66
- field :last_name , 10, '11-20', :alphanumeric
65
+ field :first_name, 10, '1-10' , :alphanumeric
66
+ field :last_name , 10, '11-20', :alphanumeric
67
67
 
68
- field_value :first_name, -> { 'Sarah' }
68
+ field_value :first_name, -> { 'Sarah' }
69
69
 
70
- def last_name
71
- 'Kerrigan'
72
- end
70
+ def last_name
71
+ 'Kerrigan'
73
72
  end
73
+ end
74
74
 
75
+ it 'should generate fixed width record' do
75
76
  PersonRecordE.new.generate.should eq "Sarah Kerrigan \n"
76
- PersonRecordE.new.generate(true).should eq File.read('spec/fixtures/debug_record.txt')
77
+ end
78
+
79
+ context 'when using the debug flag' do
80
+ it 'should produce a debug log' do
81
+ PersonRecordE.new.generate(true).should eq File.read('spec/fixtures/debug_record.txt')
82
+ end
83
+ end
84
+ end
85
+
86
+ context 'when dealing with multi-byte characters' do
87
+ it 'should generate fixed width record' do
88
+ class PersonRecordMultibyte < Fixy::Record
89
+ include Fixy::Formatter::Alphanumeric
90
+
91
+ set_record_length 9
92
+
93
+ field :name, 9, '1-9' , :alphanumeric
94
+
95
+ field_value :name, -> { "12345678И" }
96
+ end
97
+
98
+ value = PersonRecordMultibyte.new.generate
99
+ value.should be_valid_encoding
100
+ value.should == "12345678 \n"
77
101
  end
78
102
  end
79
103
 
@@ -132,4 +156,16 @@ describe 'Generating a Record' do
132
156
  end
133
157
  end
134
158
  end
135
- end
159
+
160
+ context 'when a block is passed to field' do
161
+ class PersonRecordJ < Fixy::Record
162
+ include Fixy::Formatter::Alphanumeric
163
+ set_record_length 20
164
+ field(:description , 20, '1-20', :alphanumeric) { 'Use My Value' }
165
+ end
166
+
167
+ it 'uses the proc conversion as the field value' do
168
+ PersonRecordJ.new.generate.should eq('Use My Value'.ljust(20) << "\n")
169
+ end
170
+ end
171
+ end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Omar Skalli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-13 00:00:00.000000000 Z
11
+ date: 2015-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Library for generating fixed width flat files.
@@ -59,7 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
62
+ - ".gitignore"
63
63
  - CHANGELOG.md
64
64
  - Gemfile
65
65
  - LICENSE.txt
@@ -88,12 +88,12 @@ require_paths:
88
88
  - lib
89
89
  required_ruby_version: !ruby/object:Gem::Requirement
90
90
  requirements:
91
- - - '>='
91
+ - - ">="
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - '>='
96
+ - - ">="
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  requirements: []