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

#initialize(resource_id, resource_component_id, barcode, indicator) ⇒ InstanceKey

Returns a new instance of InstanceKey.



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

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

#barcodeObject

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

#indicatorObject

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

#resource_component_idObject

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

#resource_idObject

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

.from_row(row) ⇒ Object



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# 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

.stringify(value) ⇒ Object



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

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

Instance Method Details

#to_bytesObject



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

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

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  barcode || indicator
end