Class: Eddy::Summary::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/eddy/summary/segment.rb

Overview

A collection of Data Elements. Used in Companion Guides to define a Transaction Set.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializevoid



41
42
43
# File 'lib/eddy/summary/segment.rb', line 41

def initialize()
  self.elements = []
end

Instance Attribute Details

#element_countInteger

Number of Data Elements included in the Segment.

Returns:

  • (Integer)


29
30
31
# File 'lib/eddy/summary/segment.rb', line 29

def element_count
  @element_count
end

#elementsArray<Eddy::Summary::Element>

Number of Data Elements included in the Segment.

Returns:



38
39
40
# File 'lib/eddy/summary/segment.rb', line 38

def elements
  @elements
end

#idString

Short string identifying the Segment.

Returns:

  • (String)


11
12
13
# File 'lib/eddy/summary/segment.rb', line 11

def id
  @id
end

#levelString

Indicates where the Segment is located in the Transaction Set.

Returns:

  • (String)


35
36
37
# File 'lib/eddy/summary/segment.rb', line 35

def level
  @level
end

#max_useInteger

Number of times a particular Segment may be repeated at its location in the Transaction Set.

Returns:

  • (Integer)


20
21
22
# File 'lib/eddy/summary/segment.rb', line 20

def max_use
  @max_use
end

#nameString

Full name of the Segment.

Returns:

  • (String)


14
15
16
# File 'lib/eddy/summary/segment.rb', line 14

def name
  @name
end

#notesString

Syntax, Semantic, or Comment notes on a Segment.

Returns:

  • (String)


23
24
25
# File 'lib/eddy/summary/segment.rb', line 23

def notes
  @notes
end

#posString

Indicates the order in which Segments should appear in their Level of the Transaction Set.

Returns:

  • (String)


8
9
10
# File 'lib/eddy/summary/segment.rb', line 8

def pos
  @pos
end

#purposeString

Documents the purpose of a Segment.

Returns:

  • (String)


17
18
19
# File 'lib/eddy/summary/segment.rb', line 17

def purpose
  @purpose
end

#reqString

Defines if/how the Segment is required.

Returns:

  • (String)


32
33
34
# File 'lib/eddy/summary/segment.rb', line 32

def req
  @req
end

#usageString

Indicates whether or not the Segment must be used; Somewhat redundant due to Req.

Returns:

  • (String)


26
27
28
# File 'lib/eddy/summary/segment.rb', line 26

def usage
  @usage
end

Class Method Details

.create(params = {}) ⇒ self

Parameters:

  • params (Hash) (defaults to: {})

Returns:

  • (self)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/eddy/summary/segment.rb', line 47

def self.create(params = {})
  s = new()
  s.pos           = params[:pos]
  s.id            = params[:id]
  s.name          = params[:name]
  s.purpose       = params[:purpose]
  s.max_use       = params[:max_use]
  s.notes         = params[:notes]
  s.usage         = params[:usage]
  s.element_count = params[:element_count]
  s.req           = params[:req]
  s.level         = params[:level]
  s.process_elements(params[:elements])
  return s
end

.default_for_id(id) ⇒ self

Parameters:

  • id (String)

Returns:

  • (self)

Raises:



73
74
75
76
77
78
79
80
81
82
# File 'lib/eddy/summary/segment.rb', line 73

def self.default_for_id(id)
  id.downcase!
  if ["ge", "gs", "iea", "isa", "se", "st"].include?(id)
    path = File.join(Eddy::Util.data_dir, "segments", "envelope", "#{id}.segment.yml")
    return self.from_file(path)
  end
  path = File.join(Eddy::Util.data_dir, "segments", "#{id}.segment.yml")
  raise Eddy::Errors::Error, "No segment found with id #{id}" unless File.file?(path)
  return self.from_file(path)
end

.from_file(path) ⇒ self

Parameters:

  • path (String)

    Path to a JSON or YAML file containing a valid Segment definition.

Returns:

  • (self)

Raises:



65
66
67
68
69
# File 'lib/eddy/summary/segment.rb', line 65

def self.from_file(path)
  raise Eddy::Errors::Error, "Invalid segment definition" unless Eddy::Summary.valid_segment_data?(path)
  data = Eddy::Util.read_json_or_yaml(path)
  return Eddy::Summary::Segment.create(data)
end

Instance Method Details

#build_as_segment?Boolean

Helper function to simplify conditional logic in Build.

Returns:

  • (Boolean)

    (true) Always returns true.

See Also:

  • Eddy::Summary::Segment.{Eddy{Eddy::Summary{Eddy::Summary::Loop{Eddy::Summary::Loop#treat_as_segment?}


118
119
120
# File 'lib/eddy/summary/segment.rb', line 118

def build_as_segment?()
  return true
end

#doc_comment(header: true) ⇒ String

Generate a description to use as a doc comment for a segment.

Parameters:

  • header (Boolean) (defaults to: true)

    (true)

Returns:

  • (String)


103
104
105
106
107
108
109
110
111
112
# File 'lib/eddy/summary/segment.rb', line 103

def doc_comment(header: true)
  parts = []
  parts << "### Segment Summary:\n" if header
  parts << <<~YARD.strip
    - Id: #{self.id}
    - Name: #{self.name}
    - Purpose: #{self.purpose}
  YARD
  return parts.compact.join("\n")
end

#process_elements(elements) ⇒ void

This method returns an undefined value.

TODO: Only use defaults if not enough info is provided. TODO: Define enough info.

Parameters:

  • elements (Array<Hash>)


89
90
91
92
93
94
95
96
97
# File 'lib/eddy/summary/segment.rb', line 89

def process_elements(elements)
  return if elements.nil?
  elements.each do |el|
    default_el = Eddy::Summary::Element.default_for_id(el[:id])
    default_el.ref = el[:ref]
    default_el.req = el[:req] || nil
    self.elements << default_el
  end
end