Class: Tapyrus::PSTT::Proprietary

Inherits:
Object
  • Object
show all
Defined in:
lib/tapyrus/pstt/proprietary.rb

Overview

A proprietary record, for applications that need non-standardized fields.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier:, subtype:, subkeydata: "".b, value: "".b) ⇒ Proprietary

Returns a new instance of Proprietary.



21
22
23
24
25
26
# File 'lib/tapyrus/pstt/proprietary.rb', line 21

def initialize(identifier:, subtype:, subkeydata: "".b, value: "".b)
  @identifier = identifier
  @subtype = subtype
  @subkeydata = subkeydata
  @value = value
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



7
8
9
# File 'lib/tapyrus/pstt/proprietary.rb', line 7

def identifier
  @identifier
end

#subkeydataObject (readonly)

Returns the value of attribute subkeydata.



15
16
17
# File 'lib/tapyrus/pstt/proprietary.rb', line 15

def subkeydata
  @subkeydata
end

#subtypeObject (readonly)

Returns the value of attribute subtype.



11
12
13
# File 'lib/tapyrus/pstt/proprietary.rb', line 11

def subtype
  @subtype
end

#valueString

Returns the value data with binary format.

Returns:

  • (String)

    the value data with binary format.



19
20
21
# File 'lib/tapyrus/pstt/proprietary.rb', line 19

def value
  @value
end

Class Method Details

.parse_from_record(record) ⇒ Tapyrus::PSTT::Proprietary

Parse a proprietary record.

Parameters:

Returns:



31
32
33
34
35
36
# File 'lib/tapyrus/pstt/proprietary.rb', line 31

def self.parse_from_record(record)
  buf = StringIO.new(record.keydata)
  identifier = PSTT.read_bytes(buf, PSTT.read_compact_size(buf))
  subtype = PSTT.read_compact_size(buf)
  new(identifier: identifier, subtype: subtype, subkeydata: buf.read || "".b, value: record.value)
end

Instance Method Details

#==(other) ⇒ Object



49
50
51
# File 'lib/tapyrus/pstt/proprietary.rb', line 49

def ==(other)
  other.is_a?(Proprietary) && to_keydata == other.to_keydata && value == other.value
end

#to_keydataString

Returns the key data of this record with binary format.

Returns:

  • (String)

    the key data of this record with binary format.



39
40
41
# File 'lib/tapyrus/pstt/proprietary.rb', line 39

def to_keydata
  Tapyrus.pack_var_string(identifier) + Tapyrus.pack_var_int(subtype) + subkeydata
end

#to_record(type) ⇒ Tapyrus::PSTT::KeyValue

Parameters:

  • type (Integer)

    the key type of the proprietary field in the map this record belongs to.

Returns:



45
46
47
# File 'lib/tapyrus/pstt/proprietary.rb', line 45

def to_record(type)
  KeyValue.new(type, to_keydata, value)
end