Skip to content

Commit

Permalink
added file structure. First specs pass
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoertink committed Dec 7, 2022
1 parent 7623237 commit 7d2a083
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 5 deletions.
23 changes: 23 additions & 0 deletions spec/nacha/file_header_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "../spec_helper"

describe Nacha::FileHeader do
describe "build" do
it "formats the data correctly" do
example = "101 021406766 8723856712212071417A094101Bank of Specialty JSTV Enterprises "

current_time = Time.utc(2022, 12, 7, 14, 17, 0)

io = IO::Memory.new
file_header = Nacha::FileHeader.new(
immediate_destination: "021406766",
immediate_origin: "872385671",
immediate_destination_name: "Bank of Specialty",
immediate_origin_name: "JSTV Enterprises",
file_creation_date: current_time,
file_creation_time: current_time,
)
file_header.build(io)
io.to_s.should eq(example)
end
end
end
4 changes: 0 additions & 4 deletions spec/nacha_spec.cr
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
require "./spec_helper"

describe Nacha do
# TODO: Write tests

it "works" do
false.should eq(true)
end
end
1 change: 1 addition & 0 deletions src/nacha.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require "./nacha/mixins/*"
require "./nacha/**"

module Nacha
Expand Down
2 changes: 2 additions & 0 deletions src/nacha/batch_control.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Nacha
class BatchControl
TYPE_CODE = 8

def initialize
end
end
Expand Down
2 changes: 2 additions & 0 deletions src/nacha/batch_header.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Nacha
class BatchHeader
TYPE_CODE = 5

def initialize
end
end
Expand Down
2 changes: 2 additions & 0 deletions src/nacha/entry_detail.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Nacha
class EntryDetail
TYPE_CODE = 6

def initialize
end
end
Expand Down
8 changes: 8 additions & 0 deletions src/nacha/entry_detail_addenda.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Nacha
class EntryDetailAddenda
TYPE_CODE = 7

def initialize
end
end
end
2 changes: 2 additions & 0 deletions src/nacha/file_control.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Nacha
class FileControl
TYPE_CODE = 9

def initialize
end
end
Expand Down
39 changes: 38 additions & 1 deletion src/nacha/file_header.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
module Nacha
# This record includes your company name and
# company number. It also designates the immediate destination (LaSalle Bank
# N.A. or Standard Federal Bank) of the entries contained within the file.
class FileHeader
def initialize
include BuildableRecord

TYPE_CODE = 1 # Identifies this is the FileHeader
PRIORITY_CODE = 1 # lower number is higher priority (but only 01 is used)

def initialize(
@immediate_destination : String, # The Primary bank Routing number
@immediate_origin : String, # The Primary company EIN or ABN AMRO number
@immediate_destination_name : String, # The Primary bank name
@immediate_origin_name : String, # The Primary company's name
@file_creation_date : Time = Time.utc, # File creation date Formatted as YYMMDD
@file_creation_time : Time = Time.utc, # File creation time Formatted as HHMM
@file_id_modifier : Char = 'A', # Each file submitted in the same day must update this to the next consecutive letter, then 0-9
@record_size : Int32 = 94, # The number of bytes per record row
@blocking_factor : String = "10", # wat
@format_code : String = "1", # Placeholder for future other formats
@reference_code : String? = nil # Used for your own internal accounting
)
end

def build(io : IO) : IO
io << TYPE_CODE.to_s
io << PRIORITY_CODE.to_s.rjust(2, '0')
io << @immediate_destination.rjust(10, ' ')
io << @immediate_origin.rjust(10, ' ')
io << @file_creation_date.to_s("%y%m%d")
io << @file_creation_time.to_s("%H%M")
io << @file_id_modifier.to_s
io << @record_size.to_s.rjust(3, '0')
io << @blocking_factor
io << @format_code
io << @immediate_destination_name[0..22].ljust(23, ' ')
io << @immediate_origin_name[0..22].ljust(23, ' ')
io << @reference_code.to_s.ljust(8, ' ')
io
end
end
end
4 changes: 4 additions & 0 deletions src/nacha/mixins/buildable_record.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module BuildableRecord
# This turns the record in to it's data line
abstract def build(io : IO) : IO
end

0 comments on commit 7d2a083

Please sign in to comment.