class TranslateYamlGenerator::Reader::XlsxReader
Constants
- RE_XLSX
Public Instance Methods
check_filename(filename)
click to toggle source
# File lib/translate_yaml_generator/reader.rb, line 29 def check_filename(filename) raise ArgumentError, "not vaild xlsx file" unless filename =~ RE_XLSX end
read_records(filename)
click to toggle source
# File lib/translate_yaml_generator/reader.rb, line 33 def read_records(filename) workbook = RubyXL::Parser.parse filename worksheet = workbook[0] records = [] worksheet.each_with_index do |row, row_idx| ns_cell = row[0] name_cell = row[1] # allow empty namespace ns = (defined? ns_cell.value) ? (ns_cell.value) : "" # empty name is not allowed next unless defined? name_cell.value rowdata = ns, name_cell.value (2...row.size).each do |col_idx| item_cell = row[col_idx] rowdata << item_cell.value end record = TranslateYamlGenerator::Record.new rowdata records << record end return records end