Sha256: 3b1a07dac4bc49a3420caac69bfca89181160b978035c48bd80034ba91a16615
Contents?: true
Size: 1.86 KB
Versions: 6
Compression:
Stored size: 1.86 KB
Contents
#!/usr/bin/env ruby require 'creek' require 'pp' require 'pathname' require 'fileutils' require_relative '../lib/tc211/termbase.rb' # require 'pry' filepath = ARGV[0] #'./tc211-termbase.xlsx' if filepath.nil? puts 'Error: no filepath given as first argument.' exit 1 end if Pathname.new(filepath).extname != ".xlsx" puts 'Error: filepath given must have extension .xlsx.' exit 1 end workbook = Tc211::Termbase::TermWorkbook.new(filepath) # pp workbook.glossary_info.metadata_section.structure # pp workbook.glossary_info.metadata_section.attributes registries = {} workbook.languages_supported.map do |lang| puts "************** WORKING ON LANGUAGE (#{lang})" sheet = workbook.language_sheet(lang) termsec = sheet.terms_section mdsec = sheet.metadata_section registries[sheet.language_code] = { metadata: mdsec.to_hash["metadata"], terms: termsec.terms } end output_dir = Dir.pwd metadata = { 'header' => workbook.glossary_info.metadata_section.to_hash["metadata"] } # Write registry metadata metadata['languages'] = registries.inject({}) do |acc, (lang, data)| acc.merge({lang => data[:metadata]}) end File.open(File.join(output_dir, Pathname.new(filepath).basename.sub_ext(".meta.yaml")),"w") do |file| file.write(metadata.to_yaml) end collection = Tc211::Termbase::ConceptCollection.new registries.each_pair do |lang, data| data[:terms].each do |term| collection.add_term(term) end end # collection[1206].inspect collection_output_dir = File.join(output_dir, "concepts") FileUtils.mkdir_p(collection_output_dir) concept_collection = collection.to_concept_collection concept_collection.save_to_files(collection_output_dir) # french = workbook.language_sheet("French") # french.sections[3].structure # french.sections[3].terms # english = workbook.language_sheet("English") # english.terms_section # english.terms_section.terms #pry.binding
Version data entries
6 entries across 6 versions & 1 rubygems