Class: RTP::ExtendedPlan

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

Overview

Note:

Relations:

  • Parent: Plan

  • Children: none

The Extended plan class.

Instance Attribute Summary collapse

Attributes inherited from Record

#crc, #keyword

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Record

#encode, #get_parent, #load, #to_record, #values

Constructor Details

#initialize(parent) ⇒ ExtendedPlan

Creates a new ExtendedPlan.

Parameters:

  • parent (Record)

    a record which is used to determine the proper parent of this instance



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rtp-connect/extended_plan.rb', line 32

def initialize(parent)
  super('EXTENDED_PLAN_DEF', 4, 4)
  # Parent relation (may get more than one type of record here):
  @parent = get_parent(parent.to_record, Plan)
  @parent.add_extended_plan(self)
  @attributes = [
    # Required:
    :keyword,
    :encoding,
    :fullname
  ]
end

Instance Attribute Details

#encodingObject

Returns the value of attribute encoding.



13
14
15
# File 'lib/rtp-connect/extended_plan.rb', line 13

def encoding
  @encoding
end

#fullnameObject

Returns the value of attribute fullname.



14
15
16
# File 'lib/rtp-connect/extended_plan.rb', line 14

def fullname
  @fullname
end

#parentObject (readonly)

The Record which this instance belongs to.



12
13
14
# File 'lib/rtp-connect/extended_plan.rb', line 12

def parent
  @parent
end

Class Method Details

.load(string, parent) ⇒ ExtendedPlan

Creates a new ExtendedPlan by parsing a RTPConnect string line.

Parameters:

  • string (#to_s)

    the extended plan definition record string line

  • parent (Record)

    a record which is used to determine the proper parent of this instance

Returns:

Raises:

  • (ArgumentError)

    if given a string containing an invalid number of elements



23
24
25
26
# File 'lib/rtp-connect/extended_plan.rb', line 23

def self.load(string, parent)
  ep = self.new(parent)
  ep.load(string)
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Checks for equality.

Other and self are considered equivalent if they are of compatible types and their attributes are equivalent.

Parameters:

  • other

    an object to be compared with self.

Returns:

  • (Boolean)

    true if self and other are considered equivalent



53
54
55
56
57
# File 'lib/rtp-connect/extended_plan.rb', line 53

def ==(other)
  if other.respond_to?(:to_extended_plan)
    other.send(:state) == state
  end
end

#childrenArray

Gives an empty array, as these instances are child-less by definition.

Returns:

  • (Array)

    an emtpy array



65
66
67
# File 'lib/rtp-connect/extended_plan.rb', line 65

def children
  return Array.new
end

#hashFixnum

Note:

Two objects with the same attributes will have the same hash code.

Computes a hash code for this object.

Returns:

  • (Fixnum)

    the object’s hash code



75
76
77
# File 'lib/rtp-connect/extended_plan.rb', line 75

def hash
  state.hash
end

#to_extended_planExtendedPlan

Returns self.

Returns:



83
84
85
# File 'lib/rtp-connect/extended_plan.rb', line 83

def to_extended_plan
  self
end

#to_sString Also known as: to_str

Encodes the ExtendedPlan object + any hiearchy of child objects, to a properly formatted RTPConnect ascii string.

Returns:

  • (String)

    an RTP string with a single or multiple lines/records



92
93
94
95
96
97
98
99
100
# File 'lib/rtp-connect/extended_plan.rb', line 92

def to_s
  str = encode
  if children
    children.each do |child|
      str += child.to_s
    end
  end
  return str
end