Class: Bakong::Khqr::TagLengthString

Inherits:
Object
  • Object
show all
Defined in:
lib/bakong/khqr/tag_length_string.rb

Overview

EMVCo TLV primitive: a 2-char tag, 2-digit zero-padded length, and value. Length is the character count of the value (matches the JS upstream’s ‘String.length`, which counts UTF-16 code units — equivalent to Ruby’s ‘String#length` for any character in the BMP, which covers Khmer).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, value) ⇒ TagLengthString

Returns a new instance of TagLengthString.



12
13
14
15
16
17
# File 'lib/bakong/khqr/tag_length_string.rb', line 12

def initialize(tag, value)
  @tag = tag
  @value = value
  len = value.to_s.length
  @length = len < 10 ? "0#{len}" : len.to_s
end

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



10
11
12
# File 'lib/bakong/khqr/tag_length_string.rb', line 10

def length
  @length
end

#tagObject (readonly)

Returns the value of attribute tag.



10
11
12
# File 'lib/bakong/khqr/tag_length_string.rb', line 10

def tag
  @tag
end

#valueObject (readonly)

Returns the value of attribute value.



10
11
12
# File 'lib/bakong/khqr/tag_length_string.rb', line 10

def value
  @value
end

Instance Method Details

#to_sObject



19
20
21
# File 'lib/bakong/khqr/tag_length_string.rb', line 19

def to_s
  "#{@tag}#{@length}#{@value}"
end