class Twb::Util::FieldDomainLoader
Attributes
csvOption[RW]
datasource[RW]
domains[R]
workboook[RW]
xmllocation[RW]
Public Class Methods
new()
click to toggle source
# File lib/twb/util/fielddomainloader.rb, line 30 def initialize init reset end
Public Instance Methods
initCSV(opt)
click to toggle source
# File lib/twb/util/fielddomainloader.rb, line 42 def initCSV opt @csvFile = CSV.open(@xmllocation + '/FieldDomains.csv', opt ) if 'w'.eql? opt @csvFile << ['Workbook', 'Data Source', 'Field', 'Value'] end end
load()
click to toggle source
# File lib/twb/util/fielddomainloader.rb, line 49 def load path = @xmllocation + '/*.xlsx' Dir.glob(path) do |fileName| end end
loadDataSource(ds)
click to toggle source
# File lib/twb/util/fielddomainloader.rb, line 67 def loadDataSource ds @datasource = ds.uiname fieldDomains = loadxlsx(@xmllocation + '/' + @datasource + '.xlsx') end
loadWorkbook(twb)
click to toggle source
# File lib/twb/util/fielddomainloader.rb, line 55 def loadWorkbook twb @workbook = twb.name dsFieldDomains = {} dss = twb.datasources dsFieldDomains = {} dss.each do |ds| fieldDomains = loadDataSource ds dsFieldDomains[ds.uiname] = fieldDomains end return dsFieldDomains end
loadxlsx(fileName)
click to toggle source
# File lib/twb/util/fielddomainloader.rb, line 72 def loadxlsx fileName fieldDomains = {} # TODO - fix this - when Creek::Book is in place, the twb gem cannot be loaded in Ruby on Rails, as of Jan 26, 2019 # - commenting out to sidestep problem giving up functionality for expedience in gtting online # if File.file?(fileName) # xlsx = Creek::Book.new fileName # sheets = xlsx.sheets # sheets.each do |sheet| # rows = sheet.rows.to_a # if rows.count > 1 # fieldValues = parseRows(rows) # unless fieldValues.empty? || fieldValues.values.first.empty? # fieldDomains[fieldValues.keys.first] = fieldValues.values.first # end # end # end # else # alert "#### ALERT #### Twb:'#{@workbook}' DS: '#{@datasource}' DomRef: #{fileName}' file does not exist." # end # return fieldDomains end
parseRows(rows)
click to toggle source
# File lib/twb/util/fielddomainloader.rb, line 94 def parseRows rows fieldValues = {} unless rows.empty? firstRow = rows[0].to_a[0] fieldName = firstRow[1].to_s fieldValues[fieldName] = SortedSet.new values = rows[1..-1] values.each do |row| value = row.to_a[0][1].to_s fieldValues[fieldName] << value end end return fieldValues end
reset()
click to toggle source
# File lib/twb/util/fielddomainloader.rb, line 35 def reset @workbok = nil @xmllocation = @@xmlLocation @csvOption = 'w' initCSV @csvOption end