Class: Twb::CalculationField

Inherits:
Object
  • Object
show all
Includes:
Comparable, TabTool
Defined in:
lib/twb/fieldcalculation.rb

Constant Summary

Constants included from TabTool

TabTool::TTDOCDIR

Instance Attribute Summary collapse

Attributes included from TabTool

#alerts, #docfiles, #funcdoc, #licensed, #logfilename, #logger, #loglevel, #metrics, #properties, #ttdocdir, #uuid

Instance Method Summary collapse

Methods included from TabTool

#addDocFile, #alert, #docFile, #docFileMaxNameLen, #docfilesdoc, #emit, #emitCSV, #finis, #init, #initCSV, #initDocDir, #initLogger, #license=, #licensed?

Constructor Details

#initialize(code, datasource) ⇒ CalculationField

Returns a new instance of CalculationField.



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/twb/fieldcalculation.rb', line 238

def initialize code, datasource
  # puts "\n\nCalculationField ::  %-25s  |  %s  " % [datasource.uiname, code]

  @dataSource       = datasource
  @dataSourceName   = datasource.uiname
  @dataSourceRef    = :local
  @dataSourceExists = true
  @techUIdiff       = false
  @uiname           = ''
  rawCode  = code.gsub(/^\[|\]$/,'')
  parts    = rawCode.split('].[')
  #puts "Field: #{code}  \t parts: #{parts.length} - #{parts.inspect}"

  if parts.length == 1
    @name = parts[0]
    @techCode = "[#{parts[0]}]"
    #puts "@name: #{@name}"

    if datasource.nil?
      # puts 'a'

      @uiname = @name
      @uiCode = @techCode
      @techUIdiff = false
    else # !datasource.nil?

      # puts 'b'

      #puts "b - found uiname for '#{@name}'?: #{!datasource.fieldUIName(@name).nil?} \t is:#{datasource.fieldUIName(@name)} "

      @uiname = datasource.fieldUIName(@name).nil? ? @name : datasource.fieldUIName(@name) 
      @uiCode = @uiname.nil? ? @techCode :  "[#{@uiname}]"
      @techUIdiff = !@techCode.eql?(@uiCode)
      # puts ":b #{datasource.fieldUIName(@name).nil?}  ... #{@name}  ... #{@uiname}"

      # puts "CalculationField ::       uin: %-25s | @name:%-s" % [@uiname,@name]

    end
  else # parts.length <> 1

    # puts 'c'

    rdstech   = parts[0]
    calcField = parts[1]
    @uiname   = calcField
    @dataSourceName = rdstech
    @dataSourceRef  = :remote
    @techCode = "[#{rdstech}].[#{calcField}]"
    workbook  = datasource.workbook
    @dataSource  = workbook.nil? ? nil : workbook.datasource(rdstech)
   # puts "\t  twb: #{workbook.class}  /  remoteds: #{remoteds.class}  : #{remoteds.nil? ? "<<NOT FOUND:#{rdstech}:>>" : remoteds.uiname} "

    #--

    if @dataSource.nil? || @dataSource.fieldUIName(calcField).nil?
      # puts 'd'

      @uiname     = calcField
      @uiCode     = "[<<NOT FOUND>>#{rdstech}].[#{calcField}]"
      @techUIdiff = true
      @dataSourceExists = false
    else  # !remoteds.nil?

      # puts 'e'

      @dataSourceName = @dataSource.uiname
      @uiname         = @dataSource.fieldUIName(calcField)
      @uiCode         = "[#{@dataSourceName}].[#{@uiname}]"
      @techUIdiff     = !@techCode.eql?(@uiCode)
      @dataSourceExists = true
    end
  end
  # puts "\t     dsName: #{@dataSourceName}"

  # puts "\t   @name: #{@name}"

  # puts "\t     uiname: #{@uiname}"

  @fqName = "#{@dataSourceName}::#{@uiname}"
  @type   = if @dataSource.nil?
               :CalculatedField
            else
               @dataSource.calculatedField(@uiname).nil? ? :DatabaseField : :CalculatedField
            end
end

Instance Attribute Details

#dataSourceObject (readonly)

Returns the value of attribute dataSource.



234
235
236
# File 'lib/twb/fieldcalculation.rb', line 234

def dataSource
  @dataSource
end

#dataSourceExistsObject (readonly)

Returns the value of attribute dataSourceExists.



234
235
236
# File 'lib/twb/fieldcalculation.rb', line 234

def dataSourceExists
  @dataSourceExists
end

#dataSourceNameObject (readonly)

Returns the value of attribute dataSourceName.



234
235
236
# File 'lib/twb/fieldcalculation.rb', line 234

def dataSourceName
  @dataSourceName
end

#dataSourceRefObject (readonly)

Returns the value of attribute dataSourceRef.



234
235
236
# File 'lib/twb/fieldcalculation.rb', line 234

def dataSourceRef
  @dataSourceRef
end

#fqNameObject (readonly)

Returns the value of attribute fqName.



235
236
237
# File 'lib/twb/fieldcalculation.rb', line 235

def fqName
  @fqName
end

#nameObject (readonly)

Returns the value of attribute name.



232
233
234
# File 'lib/twb/fieldcalculation.rb', line 232

def name
  @name
end

#techCodeObject (readonly)

Returns the value of attribute techCode.



232
233
234
# File 'lib/twb/fieldcalculation.rb', line 232

def techCode
  @techCode
end

#techUIdiffObject (readonly)

Returns the value of attribute techUIdiff.



236
237
238
# File 'lib/twb/fieldcalculation.rb', line 236

def techUIdiff
  @techUIdiff
end

#typeObject (readonly)

Returns the value of attribute type.



235
236
237
# File 'lib/twb/fieldcalculation.rb', line 235

def type
  @type
end

#uiCodeObject (readonly)

Returns the value of attribute uiCode.



233
234
235
# File 'lib/twb/fieldcalculation.rb', line 233

def uiCode
  @uiCode
end

#uinameObject (readonly)

Returns the value of attribute uiname.



233
234
235
# File 'lib/twb/fieldcalculation.rb', line 233

def uiname
  @uiname
end

Instance Method Details

#<=>(other) ⇒ Object



309
310
311
312
313
314
315
316
# File 'lib/twb/fieldcalculation.rb', line 309

def <=>(other)
  # myName    = @uiname.nil? ? '' : @uiname

  # otherName = other.uiName.nil? ? "" : other.uiName

  # # puts "#{@uiname} / #{myName} <=>  #{otherName} / #{other.uiName}"

  # # puts "#{@uiname.nil?} // #{other.uiName.nil?}"

  # myName <=> otherName

  @fqName <=> other.fqName
end

#idObject

initialize



305
306
307
# File 'lib/twb/fieldcalculation.rb', line 305

def id
  @id ||= @id = "#{@dataSourceName}::#{@uiname}"
end