module Metro2

Constants

ACCOUNT_STATUS
ACCOUNT_TYPE
ADDRESS_INDICATOR
ALPHANUMERIC
ALPHANUMERIC_PLUS_DASH
ALPHANUMERIC_PLUS_DOT_DASH_SLASH
COMPLIANCE_CONDITION_CODE
CONSUMER_INFORMATION_INDICATOR
CONSUMER_TRANSACTION_TYPE
CORRECTION_INDICATOR
ECOA_CODE
FIXED_LENGTH
GENERATION_CODE
INTEREST_TYPE_INDICATOR
NUMERIC
PAYMENT_HISTORY_PROFILE
PORTFOLIO_TYPE
PURCHASED_FROM_SOLD_TO_INDICATOR

K2 Segment constants

RESIDENCE_CODE
SPECIAL_COMMENT_CODE
TERMS_FREQUENCY
VERSION

Public Class Methods

account_status_needs_payment_rating?(account_status) click to toggle source
# File lib/metro_2.rb, line 190
def self.account_status_needs_payment_rating?(account_status)
  account_status.in?([ACCOUNT_STATUS[:account_transferred], ACCOUNT_STATUS[:closed],
                      ACCOUNT_STATUS[:paid_in_full_foreclosure], ACCOUNT_STATUS[:govt_insurance_claim_filed],
                      ACCOUNT_STATUS[:deed_received], ACCOUNT_STATUS[:foreclosure_completed],
                      ACCOUNT_STATUS[:voluntary_surrender]])
end
alphanumeric_to_metro2(val, required_length, permitted_chars, name) click to toggle source
# File lib/metro_2.rb, line 197
def self.alphanumeric_to_metro2(val, required_length, permitted_chars, name)
  # Left justified and blank-filled
  val = val.to_s

  return ' ' * required_length if val.empty?

  unless !!(val =~ permitted_chars)
    raise ArgumentError, "Content (#{val}) contains invalid characters in field '#{name}'"
  end

  if val.size > required_length
    val[0..(required_length - 1)]
  else
    val + (' ' * (required_length - val.size))
  end
end
numeric_to_metro2(val, required_length, is_monetary: false, name: nil, possible_values: nil) click to toggle source
# File lib/metro_2.rb, line 214
def self.numeric_to_metro2(val, required_length,
                           is_monetary: false, name: nil, possible_values: nil)
  unless possible_values.nil? || possible_values.include?(val)
    raise ArgumentError, "field #{name} has unsupported value: #{val}"
  end

  # Right justified and zero-filled
  val = val.to_s

  return '0' * required_length if val.empty?

  raise ArgumentError, "field (#{val}) must be numeric" unless !!(val =~ Metro2::NUMERIC)

  decimal_index = val.index('.')
  val = val[0..(decimal_index - 1)] if decimal_index

  # any value above 1 billion gets set to 999,999,999
  return '9' * required_length if is_monetary && val.to_f >= 1_000_000_000
  if val.size > required_length
    raise ArgumentError, "numeric field (#{val}) is too long (max #{required_length})"
  end

  ('0' * (required_length - val.size)) + val
end
version_string() click to toggle source
# File lib/metro_2/version.rb, line 6
def self.version_string
  str = VERSION.split('.')
  str[0].rjust(2, '0') + str[1].ljust(2, '0') + str[2]
end