Class: Twb::Analysis::DataSources::FieldsAliasesAnalyzer

Inherits:
Object
  • Object
show all
Includes:
TabTool
Defined in:
lib/twb/analysis/datasources/fieldsaliasesanalyzer.rb

Constant Summary collapse

@@csvFileName =
'FieldAliases.csv'
@@csvFileHeader =
[
  'Record #',
  "Workbook",
  "Data Source",
  'Field',
  'Value - Db',
  'Value - Alias'
]

Instance Attribute Summary collapse

Attributes included from TabTool

#alerts, #docDir, #docfiles, #funcdoc, #id, #licensed, #logfilename, #logger, #loglevel, #properties, #ttdocdir, #type, #uuid

Instance Method Summary collapse

Methods included from TabTool

#addDocFile, #alert, #closeDocFiles, #config, #docFile, #docFileMaxNameLen, #docfilesdoc, #docfilesdocto_s, #emit, #emitCSV, #finis, #hasConfig, #init, #initCSV, #initDocDir, #initLogger, #license=, #licensed?, #loadConfig

Constructor Details

#initialize(**args) ⇒ FieldsAliasesAnalyzer

Returns a new instance of FieldsAliasesAnalyzer.


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/twb/analysis/datasources/fieldsaliasesanalyzer.rb', line 39

def initialize(**args)
    emit "initialize FieldsAliasesAnalyzer args #{args}"
    @args      = args
    @recordDir = !@args.nil? && @args[:recordDir] == true
    @ttdocdir  = @args[:ttdocdir]
    @csvAdd    = @args[:csvMode] == :add
    @csvMode   = @csvAdd ? 'a' : 'w'
    init
    @funcdoc = {:class=>self.class, :blurb=>"Analyze Fields' Aliases", :description=>'Understanding the aliases for field values can be important and useful.',}
    #-- CSV records collectors
    # @csvFormulaFields    = Set.new
    # @csvFormulaLines     = Set.new
    #-- Counters setup --
    # @twbCount              = 0
    @dataSourcesCount   = 0
    @aliasedFieldsCount = 0
    @aliasessCount      = 0
    @recNum             = 0
    #--
    # @referencedFields     = SortedSet.new
    #--
    @csvFile   = initCSV(@@csvFileName, 'Fields and their aliased values.',                      @@csvFileHeader )
    #--
    @localEmit  = false
    # @imageFiles = Array.new
    #--
    # @doGraph = config(:dograph)
end

Instance Attribute Details

#calculatedFieldsCountObject (readonly)

Returns the value of attribute calculatedFieldsCount


26
27
28
# File 'lib/twb/analysis/datasources/fieldsaliasesanalyzer.rb', line 26

def calculatedFieldsCount
  @calculatedFieldsCount
end

#metricsObject (readonly)

Returns the value of attribute metrics


26
27
28
# File 'lib/twb/analysis/datasources/fieldsaliasesanalyzer.rb', line 26

def metrics
  @metrics
end

#referencedFieldsCountObject (readonly)

Returns the value of attribute referencedFieldsCount


26
27
28
# File 'lib/twb/analysis/datasources/fieldsaliasesanalyzer.rb', line 26

def referencedFieldsCount
  @referencedFieldsCount
end

Instance Method Details

#processAliases(field) ⇒ Object


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/twb/analysis/datasources/fieldsaliasesanalyzer.rb', line 91

def processAliases field
  aliasNodes = field.node.xpath('./aliases//alias')
  aliasNodes.each do |anode|
    key      = anode['key']
    value    = anode['value']
    numberedRec = [
                    @recNum +=1, 
                    @twbName,
                    @dsUIName,
                    @fieldName,
                    anode['key'].to_s.gsub(/^["]+/,'').gsub(/["]+$/,''),
                    anode['value']
                  ]
    #--
    if @recordDir
      @csvFile  << numberedRec.push(@twbDir)
    else
      @csvFile  << numberedRec
    end
  end
end

#processDS(ds) ⇒ Object


76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/twb/analysis/datasources/fieldsaliasesanalyzer.rb', line 76

def processDS ds
  @dsUIName  = ds.uiname
  @dsCaption = ds.caption
  @dsName    = ds.name
  #--
  ds.columnFields.each do |fld|
    if fld.hasaliases
      @fieldName    = fld.name
      @fieldCaption = fld.caption
      @fieldUIName  = fld.uiname
      processAliases(fld) 
    end
  end
end

#processTWB(twb) ⇒ Object


68
69
70
71
72
73
74
# File 'lib/twb/analysis/datasources/fieldsaliasesanalyzer.rb', line 68

def processTWB twb
  @twbName = twb.name
  @twDir   = twb.dir
  twb.datasources.each do |ds|
    processDS ds
  end
end