Class: Tc211::Termbase::TerminologySheet
- Inherits:
-
Object
- Object
- Tc211::Termbase::TerminologySheet
- Defined in:
- lib/tc211/termbase/terminology_sheet.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#language_code ⇒ Object
Returns the value of attribute language_code.
-
#sheet ⇒ Object
Returns the value of attribute sheet.
Instance Method Summary collapse
- #get_section(x) ⇒ Object
-
#initialize(sheet) ⇒ TerminologySheet
constructor
A new instance of TerminologySheet.
- #language ⇒ Object
- #metadata_section ⇒ Object
- #sections ⇒ Object
- #sections_raw ⇒ Object
-
#set_language_code(code) ⇒ Object
Read language_code from sheet.
- #terms_section ⇒ Object
Constructor Details
#initialize(sheet) ⇒ TerminologySheet
Returns a new instance of TerminologySheet.
8 9 10 11 |
# File 'lib/tc211/termbase/terminology_sheet.rb', line 8 def initialize(sheet) @sheet = sheet self end |
Instance Attribute Details
#language_code ⇒ Object
Returns the value of attribute language_code.
6 7 8 |
# File 'lib/tc211/termbase/terminology_sheet.rb', line 6 def language_code @language_code end |
#sheet ⇒ Object
Returns the value of attribute sheet.
6 7 8 |
# File 'lib/tc211/termbase/terminology_sheet.rb', line 6 def sheet @sheet end |
Instance Method Details
#get_section(x) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/tc211/termbase/terminology_sheet.rb', line 101 def get_section(x) section = nil %w(MetadataSection TermsSection).each do |t| break if section begin # puts "rows: #{x.inspect}" section = ::Tc211::Termbase.const_get(t) .new(x, { parent_sheet: self }) rescue SheetSection::RowHeaderMatchError end end section end |
#language ⇒ Object
13 14 15 |
# File 'lib/tc211/termbase/terminology_sheet.rb', line 13 def language @sheet.name end |
#metadata_section ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/tc211/termbase/terminology_sheet.rb', line 62 def sections sections.detect do |section| section.is_a?(MetadataSection) end end |
#sections ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/tc211/termbase/terminology_sheet.rb', line 70 def sections return @sections if @sections @sections = [] sections_raw.each_with_index do |x,i| section = get_section(x) unless section raise SheetSection::UnknownHeaderError.new( "Unable to find header row match for section #{i} header," + " contents: #{x.inspect}", ) end # MetadataSections always go first, so the language_code must already # be set at the time of parsing the TermsSection if section.is_a?(MetadataSection) code = section.fields["operating-language-code"] # puts "lang code is detected as #{code}, #{@language_code}" unless code.nil? # puts "setting lang code is detected as #{code}" set_language_code(code) end end puts "--------- Section #{i} is a #{section.class.name} ---------" @sections << section end end |
#sections_raw ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/tc211/termbase/terminology_sheet.rb', line 42 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!(&:empty?) raw_sections.slice_before do |row| row["A"].to_s == "Item" || row["A"].to_s.match(/^ISO 19135 Field/) end.to_a end |
#set_language_code(code) ⇒ Object
Read language_code from sheet
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tc211/termbase/terminology_sheet.rb', line 26 def set_language_code(code) # puts "language_code is #{code}" return @language_code unless @language_code.nil? @language_code = case code when "dut/nld" "dut" when "工作语言代码" "chn" when "pl" "pol" else code end end |
#terms_section ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/tc211/termbase/terminology_sheet.rb', line 54 def terms_section sections sections.detect do |section| section.is_a?(TermsSection) end end |