Class: Twb::CalculationField

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, datasource, workbook) ⇒ CalculationField

Returns a new instance of CalculationField.



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/twb/fieldcalculation.rb', line 196

def initialize code, datasource, workbook
 # puts "\nCalculationField <= \n\t  #{code}"

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

  if parts.length == 1
    @techName = parts[0]
    @techCode = "[#{parts[0]}]"
    if datasource.nil?
      @uiName = @techName
      @uiCode = @techCode
      @techUIdiff = false
    else # !datasource.nil?

      # puts "#{@techName} \t:: #{datasource.fieldUIName(@techName).nil?} \t:: #{datasource.fieldUIName(@techName)} "

      @uiName = datasource.fieldUIName(@techName).nil? ? @techName : datasource.fieldUIName(@techName) 
      @uiCode = @uiName.nil? ? @techCode :  "[#{@uiName}]"
      @techUIdiff = !@techCode.eql?(@uiCode)
    end
  else # parts.length <> 1

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

    #--

    if remoteds.nil? || remoteds.fieldUIName(calcField).nil?
      @uiName     = calcField
      @uiCode     = "[<<NOT FOUND>>#{rdstech}].[#{calcField}]"
      @techUIdiff = true
      @dataSourceExists = false
    else !remoteds.nil?
      @dataSource = remoteds.uiname
      @uiName     = remoteds.fieldUIName(calcField)
      @uiCode     = "[#{@dataSource}].[#{@uiName}]"
      @techUIdiff = !@techCode.eql?(@uiCode)
      @dataSourceExists = true
    end
  end
  @fqName = "#{@dataSource}::#{@uiName}"
end

Instance Attribute Details

#dataSourceObject (readonly)

Returns the value of attribute dataSource.



192
193
194
# File 'lib/twb/fieldcalculation.rb', line 192

def dataSource
  @dataSource
end

#dataSourceExistsObject (readonly)

Returns the value of attribute dataSourceExists.



192
193
194
# File 'lib/twb/fieldcalculation.rb', line 192

def dataSourceExists
  @dataSourceExists
end

#dataSourceRefObject (readonly)

Returns the value of attribute dataSourceRef.



192
193
194
# File 'lib/twb/fieldcalculation.rb', line 192

def dataSourceRef
  @dataSourceRef
end

#fqNameObject (readonly)

Returns the value of attribute fqName.



193
194
195
# File 'lib/twb/fieldcalculation.rb', line 193

def fqName
  @fqName
end

#techCodeObject (readonly)

Returns the value of attribute techCode.



190
191
192
# File 'lib/twb/fieldcalculation.rb', line 190

def techCode
  @techCode
end

#techNameObject (readonly)

Returns the value of attribute techName.



190
191
192
# File 'lib/twb/fieldcalculation.rb', line 190

def techName
  @techName
end

#techUIdiffObject (readonly)

Returns the value of attribute techUIdiff.



194
195
196
# File 'lib/twb/fieldcalculation.rb', line 194

def techUIdiff
  @techUIdiff
end

#uiCodeObject (readonly)

Returns the value of attribute uiCode.



191
192
193
# File 'lib/twb/fieldcalculation.rb', line 191

def uiCode
  @uiCode
end

#uiNameObject (readonly)

Returns the value of attribute uiName.



191
192
193
# File 'lib/twb/fieldcalculation.rb', line 191

def uiName
  @uiName
end

Instance Method Details

#<=>(other) ⇒ Object

initialize



246
247
248
249
250
251
252
253
# File 'lib/twb/fieldcalculation.rb', line 246

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