Module: CaTissue::Collectible

Included in:
Specimen, SpecimenCollectionGroup
Defined in:
lib/catissue/helpers/collectible.rb

Overview

A Collectible mix-in instance can hold CollectibleEventParameters}.

Instance Method Summary collapse

Instance Method Details

#collect(opts) ⇒ Object

Collects and receives this Collectible with the given options.

Parameters:

  • opts ({Symbol => Object})

    the merge options

Options Hash (opts):

  • :specimen_event_parameters (Enumerable)

    the optional SEP merge collection to augment

  • :receiver (CaTissue::User)

    the tissue bank user who received the tissue

  • :received_date (Date)

    the received date (defaults to now)

  • :collector (CaTissue::User)

    the user who acquired the tissue (defaults to the receiver)

  • :collected_date (Date)

    the collection date (defaults to the received date)

Raises:

  • (Jinx::ValidationError)

    if this Collectible has already been received



36
37
38
39
# File 'lib/catissue/helpers/collectible.rb', line 36

def collect(opts)
  raise Jinx::ValidationError.new("#{self} is already collected") if received?
  specimen_event_parameters.merge!(extract_event_parameters(opts))
end

#collected?Boolean

Returns whether this Collectible has a collected event.

Returns:

  • (Boolean)

    whether this Collectible has a collected event.



42
43
44
# File 'lib/catissue/helpers/collectible.rb', line 42

def collected?
  collection_event_parameters
end

#collectible_event_parametersObject

Returns the CaTissue::CollectibleEventParameters for this Collectible.



64
65
66
# File 'lib/catissue/helpers/collectible.rb', line 64

def collectible_event_parameters
  event_parameters.select { |ep| CaTissue::CollectibleEventParameters === ep }
end

#collection_event_parametersObject

Returns the CollectionEventParameters for this Collectible.



59
60
61
# File 'lib/catissue/helpers/collectible.rb', line 59

def collection_event_parameters
  event_parameters.detect { |ep| CaTissue::CollectionEventParameters === ep }
end

#collection_timestampDate

Returns the date this Collectible was donated by the participant.

Returns:

  • (Date)

    the date this Collectible was donated by the participant.



53
54
55
56
# File 'lib/catissue/helpers/collectible.rb', line 53

def collection_timestamp
  ep = collection_event_parameters
  ep.timestamp if ep
end

#collectorObject

Returns the User who collected this Collectible.



47
48
49
50
# File 'lib/catissue/helpers/collectible.rb', line 47

def collector
  ep = collection_event_parameters
  ep.user if ep
end

#merge_attributes(other, attributes = nil, matches = nil, &filter) ⇒ Object

Augments Jinx::Resource#merge_attributes to builds this collectible domain object’s SpecimenEventParameters. If the other source object is a Hash, then it includes both the standard attribute => value associations as well as the options described below.

Examples:

scg = CaTissue::SpecimenCollectionGroup.new(..., :collector => srg)
scg.collection_event_parameters.user #=> srg

Parameters:

  • other (Collectible, {Symbol => Object})

    other the source object or Hash

  • opts (Hash)

    a customizable set of options

Options Hash (other):

  • :specimen_event_parameters (Enumerable)

    the optional SEP merge collection to augment

  • :receiver (CaTissue::User)

    the tissue bank user who received the tissue

  • :received_date (Date)

    the received date (defaults to now)

  • :collector (CaTissue::User)

    the user who acquired the tissue (defaults to the receiver)



22
23
24
25
26
27
28
29
# File 'lib/catissue/helpers/collectible.rb', line 22

def merge_attributes(other, attributes=nil, matches=nil, &filter)
  if Hash === other then
    # extract the event parameters
    other[:specimen_event_parameters] = extract_event_parameters(other)
  end
  # delegate to super for standard attribute value merge
  super
end

#received?Boolean

Returns whether this Collectible has a received event.

Returns:

  • (Boolean)


69
70
71
# File 'lib/catissue/helpers/collectible.rb', line 69

def received?
  received_event_parameters
end

#received_event_parametersObject

Returns the ReceivedEventParameters for this Collectible.



80
81
82
# File 'lib/catissue/helpers/collectible.rb', line 80

def received_event_parameters
  event_parameters.detect { |ep| CaTissue::ReceivedEventParameters === ep }
end

#receiverObject

Returns the User who received this Collectible.



74
75
76
77
# File 'lib/catissue/helpers/collectible.rb', line 74

def receiver
  ep = received_event_parameters
  ep.user if ep
end