Sha256: 221d98a227aa12499c515da0f06d6361022b4ad95d90f0be2d233cfb81118c46

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

require_relative "metadata_section"
require_relative "terms_section"
require "iso-639"

module Tc211::Termbase

class TerminologySheet
  attr_accessor :sheet

  def initialize(sheet)
    @sheet = sheet
    self
  end

  def language
    @sheet.name
  end

  def language_code
    # Hack to make ISO_639 gem work...
    lang = case language
    when "Dutch"
      "Dutch; Flemish"
    when "Spanish"
      "Spanish; Castilian"
    else
      language
    end
    ISO_639.find_by_english_name(lang).alpha3
  rescue
    raise StandardError.new("Failed to find alpha3 code for language: #{lang}")
  end

  def sections_raw
    # Sections either start with "A" => "Item", or they have empty lines between
    raw_sections = @sheet.simple_rows.to_a

    raw_sections.reject! do |section|
      section.empty?
    end

    raw_sections = raw_sections.slice_before do |row|
      row["A"].to_s == "Item" || row["A"].to_s.match(/^ISO 19135 Field/)
    end.to_a
  end

  def terms_section
    sections

    sections.detect do |section|
      section.is_a?(TermsSection)
    end
  end

  def sections
    return @sections if @sections

    @sections = []
    sections_raw.each_with_index do |x,i|

      section = if MetadataSection.match_header(x[0])
        puts "--------- Section #{i} is a MetadataSection ---------"
        # puts "rows: #{x.inspect}"
        MetadataSection.new(x)
      else
        puts "--------- Section #{i} is a TermsSection ---------"
        # puts "rows: #{x.inspect}"
        TermsSection.new(x, {language_code: language_code})
      end

      @sections << section
    end

  end

end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tc211-termbase-0.1.4 lib/tc211/termbase/terminology_sheet.rb
tc211-termbase-0.1.2 lib/tc211/termbase/terminology_sheet.rb
tc211-termbase-0.1.1 lib/tc211/termbase/terminology_sheet.rb