Sha256: f39738dad3a7a4118434a4e0c33fb9c9a74e5855ca3605d94d4192d56cd424a9
Contents?: true
Size: 1.65 KB
Versions: 4
Compression:
Stored size: 1.65 KB
Contents
require "ginny" module Eddy module Build module Elements # @param el [Eddy::Schema::ElementSummary] # @param test [Boolean] (false) When true, returns output as a string instead of writing to a file. # @return [void] def self.id(el, test: false) code_list = self.build_code_list(el.id) return nil if code_list.nil? c = self.ginny_class( el, ("\n" + self.default_constructor(el) + "\n\n" + code_list + "\n"), # "\n#{self.default_constructor(el)}\n\n#{code_list}\n", ) return c.render if test c.generate( File.join(Eddy::Util.root_dir, "build", "elements"), file: "#{el.id}.#{Eddy::Util.snake_case(el.name)}.rb", ) return nil end # @param id [String] # @return [String] def self.build_code_list(id) file = File.join(Eddy::Util.data_dir, "004010", "code-lists", "#{id}.tsv") begin data = Eddy::Util.parse_tsv(file) rescue Errno::ENOENT puts("Missing code-list for element #{id}") return nil rescue CSV::MalformedCSVError => e puts("Error reading csv file '#{file}':#{e}") return nil end # body = "return [\n" + data.map { |c| %("#{c[:id]}").indent(2) }.join(",\n") + "\n]\n" body = "" body << "return [\n" data.each do |c| body << %("#{c[:id]}", # #{c[:definition]}\n).indent(2) end body << "]\n" return Ginny::Func.create({ name: "code_list", return_type: "Array<String>", body: body, }).render() end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
eddy-0.5.1 | lib/eddy/build/elements/id.rb |
eddy-0.5.0 | lib/eddy/build/elements/id.rb |
eddy-0.4.0 | lib/eddy/build/elements/id.rb |
eddy-0.3.0 | lib/eddy/build/elements/id.rb |