Class: Eddy::Summary::Segment
- Inherits:
-
Object
- Object
- Eddy::Summary::Segment
- 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
-
#element_count ⇒ Integer
Number of Data Elements included in the Segment.
-
#elements ⇒ Array<Eddy::Summary::Element>
Number of Data Elements included in the Segment.
-
#id ⇒ String
Short string identifying the Segment.
-
#level ⇒ String
Indicates where the Segment is located in the Transaction Set.
-
#max_use ⇒ Integer
Number of times a particular Segment may be repeated at its location in the Transaction Set.
-
#name ⇒ String
Full name of the Segment.
-
#notes ⇒ String
Syntax, Semantic, or Comment notes on a Segment.
-
#pos ⇒ String
Indicates the order in which Segments should appear in their Level of the Transaction Set.
-
#purpose ⇒ String
Documents the purpose of a Segment.
-
#req ⇒ String
Defines if/how the Segment is required.
-
#usage ⇒ String
Indicates whether or not the Segment must be used; Somewhat redundant due to
Req
.
Class Method Summary collapse
Instance Method Summary collapse
-
#build_as_segment? ⇒ Boolean
Helper function to simplify conditional logic in Build.
-
#doc_comment(header: true) ⇒ String
Generate a description to use as a doc comment for a segment.
- #initialize ⇒ void constructor
-
#process_elements(elements) ⇒ void
TODO: Only use defaults if not enough info is provided.
Constructor Details
#initialize ⇒ void
41 42 43 |
# File 'lib/eddy/summary/segment.rb', line 41 def initialize() self.elements = [] end |
Instance Attribute Details
#element_count ⇒ Integer
Number of Data Elements included in the Segment.
29 30 31 |
# File 'lib/eddy/summary/segment.rb', line 29 def element_count @element_count end |
#elements ⇒ Array<Eddy::Summary::Element>
Number of Data Elements included in the Segment.
38 39 40 |
# File 'lib/eddy/summary/segment.rb', line 38 def elements @elements end |
#id ⇒ String
Short string identifying the Segment.
11 12 13 |
# File 'lib/eddy/summary/segment.rb', line 11 def id @id end |
#level ⇒ String
Indicates where the Segment is located in the Transaction Set.
35 36 37 |
# File 'lib/eddy/summary/segment.rb', line 35 def level @level end |
#max_use ⇒ Integer
Number of times a particular Segment may be repeated at its location in the Transaction Set.
20 21 22 |
# File 'lib/eddy/summary/segment.rb', line 20 def max_use @max_use end |
#name ⇒ String
Full name of the Segment.
14 15 16 |
# File 'lib/eddy/summary/segment.rb', line 14 def name @name end |
#notes ⇒ String
Syntax, Semantic, or Comment notes on a Segment.
23 24 25 |
# File 'lib/eddy/summary/segment.rb', line 23 def notes @notes end |
#pos ⇒ String
Indicates the order in which Segments should appear in their Level of the Transaction Set.
8 9 10 |
# File 'lib/eddy/summary/segment.rb', line 8 def pos @pos end |
#purpose ⇒ String
Documents the purpose of a Segment.
17 18 19 |
# File 'lib/eddy/summary/segment.rb', line 17 def purpose @purpose end |
#req ⇒ String
Defines if/how the Segment is required.
32 33 34 |
# File 'lib/eddy/summary/segment.rb', line 32 def req @req end |
#usage ⇒ String
Indicates whether or not the Segment must be used; Somewhat redundant due to Req
.
26 27 28 |
# File 'lib/eddy/summary/segment.rb', line 26 def usage @usage end |
Class Method Details
.create(params = {}) ⇒ 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
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
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.
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.
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.
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 |