Class: Eddy::Summary::Element

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#defaultString

Default value for the Element

Returns:

  • (String)


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

def default
  @default
end

#descriptionString

Description of the Element.

Returns:

  • (String)


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

def description
  @description
end

#idString

Short string used to identify the Element.

Returns:

  • (String)


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

def id
  @id
end

#maxInteger

Maximum length for a valid Element value. Used for validation.

Returns:

  • (Integer)


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

def max
  @max
end

#minInteger

Minimum length for a valid Element value. Used for validation.

Returns:

  • (Integer)


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

def min
  @min
end

#nameString

Full name of the Element.

Returns:

  • (String)


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

def name
  @name
end

#refString

Indicates the order in which Elements should appear in their Segment.

Returns:

  • (String)


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

def ref
  @ref
end

#reqString

Defines if/how the Element is required.

Returns:

  • (String)


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

def req
  @req
end

#typeString

The kind of value the Element will contain.

Returns:

  • (String)


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

def type
  @type
end

#valid_valuesArray

A list of valid values for the Element.

Returns:

  • (Array)


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

def valid_values
  @valid_values
end

Class Method Details

.create(params = {}) ⇒ self

Parameters:

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

    ({})

Returns:

  • (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

Parameters:

  • id (String)

Returns:

  • (self)

Raises:



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.

Parameters:

  • header (Hash<:none, :ref, :see, :summary>) (defaults to: :summary)

    (:summary)

Returns:

  • (String)


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_typeString

Returns:

  • (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_nameString

Returns:

  • (String)


65
66
67
# File 'lib/eddy/summary/element.rb', line 65

def normalized_name
  return Eddy::Util.normalize_name(self.name)
end

#yard_typeString

Returns:

  • (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