Class: Metro2::Metro2File

Inherits:
Object
  • Object
show all
Includes:
Fields
Defined in:
lib/metro_2/metro2_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Fields

#alphanumeric_const_field, #alphanumeric_field, #date_field, #monetary_field, #numeric_const_field, #numeric_field, #timestamp_field

Constructor Details

#initializeMetro2File

Returns a new instance of Metro2File.



11
12
13
14
# File 'lib/metro_2/metro2_file.rb', line 11

def initialize
  @base_segments = []
  @header = Records::HeaderSegment.new
end

Instance Attribute Details

#base_segmentsObject (readonly)

Returns the value of attribute base_segments.



7
8
9
# File 'lib/metro_2/metro2_file.rb', line 7

def base_segments
  @base_segments
end

#headerObject (readonly)

Returns the value of attribute header.



8
9
10
# File 'lib/metro_2/metro2_file.rb', line 8

def header
  @header
end

#trailerObject (readonly)

Returns the value of attribute trailer.



9
10
11
# File 'lib/metro_2/metro2_file.rb', line 9

def trailer
  @trailer
end

Instance Method Details

#to_sObject



16
17
18
19
20
21
22
23
24
# File 'lib/metro_2/metro2_file.rb', line 16

def to_s
  segments = []
  segments << @header
  @base_segments.each { |base| segments << base }
  @trailer ||= trailer_from_base_segments
  segments << @trailer

  segments.collect { |r| r.to_metro2 }.join("\n") + "\n"
end

#trailer_from_base_segmentsObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/metro_2/metro2_file.rb', line 26

def trailer_from_base_segments
  status_code_count = Hash.new(0)
  num_ssn = 0
  num_dob = 0
  num_telephone = 0
  num_ecoa_code_z = 0
  total_k2_segments = 0
  j1_segment_ssn = 0
  j2_segment_ssn = 0
  j1_segment_dob = 0
  j2_segment_dob = 0
  total_j1_segments = 0
  total_j2_segments = 0

  @base_segments.each do |base|
    status_code_count[base..upcase] += 1
    num_ssn += 1 if  base.social_security_number
    num_dob += 1 if base.date_of_birth
    num_telephone += 1 if base.telephone_number
    num_ecoa_code_z += 1 if base.ecoa_code == 'Z'

    if base.j1_segment
      for j1_segment in base.j1_segment do
       num_telephone += 1 if j1_segment.telephone_number
       num_ecoa_code_z += 1 if j1_segment.ecoa_code == 'Z'
       j1_segment_ssn += 1 if j1_segment.social_security_number
       j1_segment_dob += 1 if j1_segment.date_of_birth
       total_j1_segments += 1
      end
    end

    if base.j2_segment
      for j2_segment in base.j2_segment do
        num_telephone += 1 if j2_segment.telephone_number
        num_ecoa_code_z += 1 if j2_segment.ecoa_code == 'Z'
        j2_segment_ssn += 1 if j2_segment.social_security_number
        j2_segment_dob += 1 if j2_segment.date_of_birth
        total_j2_segments += 1
      end
    end

    total_k2_segments += 1 if base.k2_segment
  end

  trailer = Records::TrailerSegment.new
  trailer.total_base_records = @base_segments.size
  trailer.total_j1_segments = total_j1_segments
  trailer.total_j2_segments = total_j2_segments
  trailer.total_status_code_df = status_code_count['DF']
  trailer.total_status_code_da = status_code_count['DA']
  trailer.total_status_code_05 = status_code_count['05']
  trailer.total_status_code_11 = status_code_count['11']
  trailer.total_status_code_13 = status_code_count['13']
  trailer.total_status_code_61 = status_code_count['61']
  trailer.total_status_code_62 = status_code_count['62']
  trailer.total_status_code_63 = status_code_count['63']
  trailer.total_status_code_64 = status_code_count['64']
  trailer.total_status_code_65 = status_code_count['65']
  trailer.total_status_code_71 = status_code_count['71']
  trailer.total_status_code_78 = status_code_count['78']
  trailer.total_status_code_80 = status_code_count['80']
  trailer.total_status_code_82 = status_code_count['82']
  trailer.total_status_code_83 = status_code_count['83']
  trailer.total_status_code_84 = status_code_count['84']
  trailer.total_status_code_88 = status_code_count['88']
  trailer.total_status_code_89 = status_code_count['89']
  trailer.total_status_code_93 = status_code_count['93']
  trailer.total_status_code_94 = status_code_count['94']
  trailer.total_status_code_94 = status_code_count['95']
  trailer.total_status_code_96 = status_code_count['96']
  trailer.total_status_code_97 = status_code_count['97']
  trailer.ecoa_code_z = num_ecoa_code_z
  trailer.total_social_security_numbers = num_ssn + j1_segment_ssn + j2_segment_ssn
  trailer.total_social_security_numbers_in_base = num_ssn
  trailer.total_social_security_numbers_in_j1 = j1_segment_ssn
  trailer.total_social_security_numbers_in_j2 = j2_segment_ssn
  trailer.total_date_of_births = num_dob + j1_segment_dob + j2_segment_dob
  trailer.total_date_of_births_in_base = num_dob
  trailer.total_date_of_births_in_j1 = j1_segment_dob
  trailer.total_date_of_births_in_j2 = j2_segment_dob
  trailer.total_telephome_numbers = num_telephone
  trailer.total_k2_segments = total_k2_segments
  trailer
end