Class: Tc211::Termbase::TermWorkbook

Inherits:
Object
  • Object
show all
Defined in:
lib/tc211/termbase/term_workbook.rb

Constant Summary collapse

SPECIAL_SHEETS =
[
  "Glossary Information",
  "Character Encoding Spreadsheet",
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ TermWorkbook

Returns a new instance of TermWorkbook.



17
18
19
20
21
22
23
24
25
# File 'lib/tc211/termbase/term_workbook.rb', line 17

def initialize(filepath)
  @filename = filepath
  @workbook = Creek::Book.new(filepath)
  @glossary_info = InformationSheet.new(
    find_sheet_by_name("Glossary Information"),
  )
  @languages = languages_supported
  self
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



10
11
12
# File 'lib/tc211/termbase/term_workbook.rb', line 10

def filename
  @filename
end

#glossary_infoObject

Returns the value of attribute glossary_info.



10
11
12
# File 'lib/tc211/termbase/term_workbook.rb', line 10

def glossary_info
  @glossary_info
end

#languagesObject

Returns the value of attribute languages.



10
11
12
# File 'lib/tc211/termbase/term_workbook.rb', line 10

def languages
  @languages
end

#workbookObject

Returns the value of attribute workbook.



10
11
12
# File 'lib/tc211/termbase/term_workbook.rb', line 10

def workbook
  @workbook
end

Instance Method Details

#find_sheet_by_name(sheet_name) ⇒ Object



39
40
41
42
43
# File 'lib/tc211/termbase/term_workbook.rb', line 39

def find_sheet_by_name(sheet_name)
  @workbook.sheets.detect do |sheet|
    sheet.name == sheet_name
  end
end

#language_sheet(lang) ⇒ Object



33
34
35
36
37
# File 'lib/tc211/termbase/term_workbook.rb', line 33

def language_sheet(lang)
  raise unless @languages.include?(lang)

  TerminologySheet.new(find_sheet_by_name(lang))
end

#languages_supportedObject



27
28
29
30
31
# File 'lib/tc211/termbase/term_workbook.rb', line 27

def languages_supported
  @workbook.sheets.map(&:name).reject! do |name|
    SPECIAL_SHEETS.include?(name)
  end
end

#write_glossary_infoObject



45
46
47
48
49
50
# File 'lib/tc211/termbase/term_workbook.rb', line 45

def write_glossary_info
  glossary_info_fn = Pathname.new(@filename).sub_ext(".yaml")
  File.open(glossary_info_fn, "w") do |file|
    file.write(glossary_info.to_yaml)
  end
end