Class: RTP::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/rtp-connect/record.rb

Overview

The Record class contains attributes and methods that are common for the various record types defined in the RTPConnect standard.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#crcObject

The CRC is used to validate the integrity of the content of the RTP string line.



11
12
13
# File 'lib/rtp-connect/record.rb', line 11

def crc
  @crc
end

#keywordObject (readonly)

The keyword defines the record type of a particular RTP string line.



9
10
11
# File 'lib/rtp-connect/record.rb', line 9

def keyword
  @keyword
end

Instance Method Details

#encodeString

Encodes a string from the contents of this instance.

This produces the full record string line, including a computed CRC checksum.

Returns:

  • (String)

    a proper RTPConnect type CSV string



28
29
30
31
32
33
# File 'lib/rtp-connect/record.rb', line 28

def encode
  content = CSV.generate_line(values, force_quotes: true, row_sep: '') + ","
  checksum = content.checksum
  # Complete string is content + checksum (in double quotes) + carriage return + line feed
  return (content + checksum.to_s.wrap + "\r\n").encode('ISO8859-1')
end

#get_parent(last_parent, klass) ⇒ Object

Follows the tree of parents until the appropriate parent of the requesting record is found.

Parameters:

  • last_parent (Record)

    the previous parent (the record from the previous line in the RTP file)

  • klass (Record)

    the expected parent record class of this record (e.g. Plan, Field)



40
41
42
43
44
45
46
# File 'lib/rtp-connect/record.rb', line 40

def get_parent(last_parent, klass)
  if last_parent.is_a?(klass)
    return last_parent
  else
    return last_parent.get_parent(last_parent.parent, klass)
  end
end

#to_recordRecord

Returns self.

Returns:



52
53
54
# File 'lib/rtp-connect/record.rb', line 52

def to_record
  self
end