Class: Bakong::Khqr::MerchantCode::MerchantCategoryCode

Inherits:
TagLengthString show all
Defined in:
lib/bakong/khqr/merchant_code/merchant_category_code.rb

Instance Attribute Summary

Attributes inherited from TagLengthString

#length, #tag, #value

Instance Method Summary collapse

Methods inherited from TagLengthString

#to_s

Constructor Details

#initialize(tag, value) ⇒ MerchantCategoryCode

Returns a new instance of MerchantCategoryCode.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bakong/khqr/merchant_code/merchant_category_code.rb', line 12

def initialize(tag, value)
  raise Error.from(ERROR_CODES[:MERCHANT_CATEGORY_TAG_REQUIRED]) if value.nil? || value == ""

  if value.length > EMV[:INVALID_LENGTH][:MERCHANT_CATEGORY_CODE]
    raise Error.from(ERROR_CODES[:MERCHANT_CODE_LENGTH_INVALID])
  end

  raise Error.from(ERROR_CODES[:INVALID_MERCHANT_CATEGORY_CODE]) unless value.match?(/\A\d+\z/)

  mcc = value.to_i
  raise Error.from(ERROR_CODES[:INVALID_MERCHANT_CATEGORY_CODE]) if mcc.negative? || mcc > 9999

  super
end