Class: Eddy::Summary::Element
- Inherits:
-
Object
- Object
- Eddy::Summary::Element
- Defined in:
- lib/eddy/summary/element.rb
Overview
An individual EDI Data Element. Used in Companion Guides to define requirements for a Segment.
Instance Attribute Summary collapse
-
#default ⇒ String
Default value for the Element.
-
#description ⇒ String
Description of the Element.
-
#id ⇒ String
Short string used to identify the Element.
-
#max ⇒ Integer
Maximum length for a valid Element value.
-
#min ⇒ Integer
Minimum length for a valid Element value.
-
#name ⇒ String
Full name of the Element.
-
#ref ⇒ String
Indicates the order in which Elements should appear in their Segment.
-
#req ⇒ String
Defines if/how the Element is required.
-
#type ⇒ String
The kind of value the Element will contain.
-
#valid_values ⇒ Array
A list of valid values for the Element.
Class Method Summary collapse
Instance Method Summary collapse
-
#doc_comment(header: :summary) ⇒ String
Generate a description to use as a doc comment for an element.
- #edi_type ⇒ String
- #normalized_name ⇒ String
- #yard_type ⇒ String
Instance Attribute Details
#default ⇒ String
Default value for the Element
29 30 31 |
# File 'lib/eddy/summary/element.rb', line 29 def default @default end |
#description ⇒ String
Description of the Element.
23 24 25 |
# File 'lib/eddy/summary/element.rb', line 23 def description @description end |
#id ⇒ String
Short string used to identify the Element.
11 12 13 |
# File 'lib/eddy/summary/element.rb', line 11 def id @id end |
#max ⇒ Integer
Maximum length for a valid Element value. Used for validation.
20 21 22 |
# File 'lib/eddy/summary/element.rb', line 20 def max @max end |
#min ⇒ Integer
Minimum length for a valid Element value. Used for validation.
17 18 19 |
# File 'lib/eddy/summary/element.rb', line 17 def min @min end |
#name ⇒ String
Full name of the Element.
14 15 16 |
# File 'lib/eddy/summary/element.rb', line 14 def name @name end |
#ref ⇒ String
Indicates the order in which Elements should appear in their Segment.
8 9 10 |
# File 'lib/eddy/summary/element.rb', line 8 def ref @ref end |
#req ⇒ String
Defines if/how the Element is required.
26 27 28 |
# File 'lib/eddy/summary/element.rb', line 26 def req @req end |
#type ⇒ String
The kind of value the Element will contain.
35 36 37 |
# File 'lib/eddy/summary/element.rb', line 35 def type @type end |
#valid_values ⇒ Array
A list of valid values for the Element.
32 33 34 |
# File 'lib/eddy/summary/element.rb', line 32 def valid_values @valid_values end |
Class Method Details
.create(params = {}) ⇒ self
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/eddy/summary/element.rb', line 39 def self.create(params = {}) summary = self.new() summary.ref = params[:ref]&.strip summary.id = params[:id]&.strip summary.name = params[:name]&.strip summary.min = params[:min]&.to_i summary.max = params[:max]&.to_i summary.description = params[:description]&.strip summary.req = params[:req]&.strip summary.default = params[:default]&.strip summary.valid_values = params[:valid_values] summary.type = params[:type]&.strip return summary end |
.default_for_id(id) ⇒ self
56 57 58 59 60 61 62 |
# File 'lib/eddy/summary/element.rb', line 56 def self.default_for_id(id) data = Eddy::Util.raw_element_data() id.upcase! result = data.find { |el| el[:id] == id } raise Eddy::Errors::Error, "No element found with id #{id}" if result.nil? return self.create(result) end |
Instance Method Details
#doc_comment(header: :summary) ⇒ String
Generate a description to use as a doc comment for an element.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/eddy/summary/element.rb', line 73 def doc_comment(header: :summary) parts = [] case header when :none, nil, false # Nothing to do when :see then return "(see Eddy::Elements::#{Eddy::Util.normalize_id(self.id)})" when :ref then parts << "### #{self.ref.upcase}\n" when :summary then parts << "### Element Summary:\n" else raise ArgumentError, "header must be a valid symbol" end parts << <<~YARD.strip - Id: #{self.id} - Name: #{self.name} - Type: #{self.type} - Min/Max: #{self.min}/#{self.max} - Description: #{self.description} YARD return parts.compact.join("\n") end |
#edi_type ⇒ String
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/eddy/summary/element.rb', line 108 def edi_type() return case self.type when "AN" then "AN" when "B" then "B" when "DT" then "DT" when "ID" then "ID" when /N\d*/ then "N" when /R\d*/ then "R" when "TM" then "TM" else raise Eddy::Errors::Error, "unable to determine element type" end end |
#normalized_name ⇒ String
65 66 67 |
# File 'lib/eddy/summary/element.rb', line 65 def normalized_name return Eddy::Util.normalize_name(self.name) end |
#yard_type ⇒ String
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/eddy/summary/element.rb', line 94 def yard_type() return case self.type when "AN" then "String" when "B" then "String" when "DT" then "Time" when "ID" then "String" when /N\d*/ then "Integer" when /R\d*/ then "Float" when "TM" then "Time" else raise Eddy::Errors::Error, "unable to determine element type" end end |