Sha256: b646ff39dfc2cbc451f1ffac9fd95d45355f0e589b7e3a4f81230fc396864bf3

Contents?: true

Size: 1.45 KB

Versions: 4

Compression:

Stored size: 1.45 KB

Contents

require "eddy/build/elements/element"
require "eddy/build/elements/n"
require "eddy/build/elements/id"

module Eddy
  # Generate Ruby classes for modeling Data Element logic, notes, and validation.
  module Build
    module Elements

      # Generate `Eddy::Element` classes for all data elements defined in `data/004010/elements.tsv`
      #
      # @param elements [Array<Eddy::Schema::ElementSummary>]
      # @return [void]
      def self.generate_elements(elements = self.generate_element_data())
        existing = (Eddy::Util.list_element_classes() + Eddy::Util.list_built_elements()).uniq()
        elements.each do |el|
          next if existing.include?(el.id)
          existing.append(el.id)
          case el.edi_type()
          when "B"  then next
          when "ID" then self.id(el)
          when "N"  then self.n(el)
          when "AN" then self.element(el)
          when "DT" then self.element(el)
          when "R"  then self.element(el)
          when "TM" then self.element(el)
          end
        end
        return nil
      end

      # Generate usable data from `data/004010/elements.tsv`.
      #
      # @return [Array<Eddy::Schema::ElementSummary>]
      def self.generate_element_data()
        data = Eddy::Util.raw_element_data()
        elements = data.map do |el|
          next if el[:type].nil? || el[:description].nil?
          Eddy::Schema::ElementSummary.create(el)
        end
        return elements.compact
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
eddy-0.5.1 lib/eddy/build/elements/elements.rb
eddy-0.5.0 lib/eddy/build/elements/elements.rb
eddy-0.4.0 lib/eddy/build/elements/elements.rb
eddy-0.3.0 lib/eddy/build/elements/elements.rb