Class: InstanceKey

Inherits:
Struct
  • Object
show all
Defined in:
backend/app/lib/user_defined_field_migrator.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (InstanceKey) initialize(resource_id, resource_component_id, barcode, indicator)

Returns a new instance of InstanceKey



306
307
308
309
310
311
# File 'backend/app/lib/user_defined_field_migrator.rb', line 306

def initialize(resource_id, resource_component_id, barcode, indicator)
  super(self.class.stringify(resource_id),
        self.class.stringify(resource_component_id),
        self.class.stringify(barcode),
        self.class.stringify(indicator))
end

Instance Attribute Details

- (Object) barcode

Returns the value of attribute barcode

Returns:

  • (Object)

    the current value of barcode



284
285
286
# File 'backend/app/lib/user_defined_field_migrator.rb', line 284

def barcode
  @barcode
end

- (Object) indicator

Returns the value of attribute indicator

Returns:

  • (Object)

    the current value of indicator



284
285
286
# File 'backend/app/lib/user_defined_field_migrator.rb', line 284

def indicator
  @indicator
end

- (Object) resource_component_id

Returns the value of attribute resource_component_id

Returns:

  • (Object)

    the current value of resource_component_id



284
285
286
# File 'backend/app/lib/user_defined_field_migrator.rb', line 284

def resource_component_id
  @resource_component_id
end

- (Object) resource_id

Returns the value of attribute resource_id

Returns:

  • (Object)

    the current value of resource_id



284
285
286
# File 'backend/app/lib/user_defined_field_migrator.rb', line 284

def resource_id
  @resource_id
end

Class Method Details

+ (Object) from_row(row)



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'backend/app/lib/user_defined_field_migrator.rb', line 286

def self.from_row(row)

  if row[:barcode].nil? && row[:container1AlphaNumIndicator].nil? && row[:container1NumericIndicator].nil?
    # This cannot be matched to a TopContainer
    return nil
  end

  barcode = stringify(row[:barcode])

  if barcode
    indicator = nil
  elsif (indicator = stringify(row[:container1AlphaNumIndicator]))
  else
    indicator = sprintf("%g", row[:container1NumericIndicator])
  end

  new(row[:resourceId], row[:resourceComponentId], barcode, indicator)
end

+ (Object) stringify(value)



314
315
316
317
318
319
320
# File 'backend/app/lib/user_defined_field_migrator.rb', line 314

def self.stringify(value)
  if value == "" || value.nil?
    nil
  else
    value.to_s
  end
end

Instance Method Details

- (Object) to_bytes



322
323
324
# File 'backend/app/lib/user_defined_field_migrator.rb', line 322

def to_bytes
  Digest::SHA1.digest(self.to_json)
end

- (Boolean) valid?

Returns:

  • (Boolean)


327
328
329
# File 'backend/app/lib/user_defined_field_migrator.rb', line 327

def valid?
  barcode || indicator
end