Class: ODDB::ActiveAgentCommon

Inherits:
Object
  • Object
show all
Includes:
Persistence
Defined in:
src/model/activeagent.rb,
test/test_model/activeagent.rb

Direct Known Subclasses

ActiveAgent

Constant Summary

Constants included from Persistence

ODBA_PREDEFINE_SERIALIZABLE

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from PersistenceMethods

#data_origin, #data_origins, #diff, #nil_if_empty, #parent, #structural_ancestors, #undiffable?, #update_values

Constructor Details

- (ActiveAgentCommon) initialize(substance_name)

A new instance of ActiveAgentCommon



14
15
16
17
# File 'src/model/activeagent.rb', line 14

def initialize(substance_name)
  super()
  @substance_name = substance_name
end

Instance Attribute Details

- (Object) chemical_dose

Returns the value of attribute chemical_dose



12
13
14
# File 'src/model/activeagent.rb', line 12

def chemical_dose
  @chemical_dose
end

- (Object) chemical_substance

Returns the value of attribute chemical_substance



11
12
13
# File 'src/model/activeagent.rb', line 11

def chemical_substance
  @chemical_substance
end

- (Object) composition

Returns the value of attribute composition



13
14
15
# File 'src/model/activeagent.rb', line 13

def composition
  @composition
end

- (Object) dose

Returns the value of attribute dose



12
13
14
# File 'src/model/activeagent.rb', line 12

def dose
  @dose
end

- (Object) equivalent_dose

Returns the value of attribute equivalent_dose



12
13
14
# File 'src/model/activeagent.rb', line 12

def equivalent_dose
  @equivalent_dose
end

- (Object) equivalent_substance

Returns the value of attribute equivalent_substance



11
12
13
# File 'src/model/activeagent.rb', line 11

def equivalent_substance
  @equivalent_substance
end

- (Object) sequence

Returns the value of attribute sequence



12
13
14
# File 'src/model/activeagent.rb', line 12

def sequence
  @sequence
end

- (Object) spagyric_dose

Returns the value of attribute spagyric_dose



13
14
15
# File 'src/model/activeagent.rb', line 13

def spagyric_dose
  @spagyric_dose
end

- (Object) spagyric_type

Returns the value of attribute spagyric_type



13
14
15
# File 'src/model/activeagent.rb', line 13

def spagyric_type
  @spagyric_type
end

- (Object) substance

Returns the value of attribute substance



10
11
12
# File 'src/model/activeagent.rb', line 10

def substance
  @substance
end

Instance Method Details

- (Object) <=>(other)



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'src/model/activeagent.rb', line 50

def <=>(other)
  od = other.dose
  if(@dose.nil? && od.nil?)
    @substance <=> other.substance
  elsif(od.nil?)
    -1
  elsif(@dose.nil?)
    1
  else
    (od <=> @dose).nonzero? \
      || (@substance <=> other.substance)
  end
end

- (Object) ==(other)



38
39
40
41
42
43
44
45
46
47
48
49
# File 'src/model/activeagent.rb', line 38

def ==(other)
  other.is_a?(ActiveAgent) \
    && [ [@substance, @dose], [@chemical_substance, @chemical_dose],
         [@equivalent_substance, @equivalent_dose]].any? { |pair| 
           [ [other.substance, other.dose],
             [other.chemical_substance, other.chemical_dose],
             [other.equivalent_substance, other.equivalent_dose],
           ].any? { |others| 
             others == pair && !pair.any? { |item| item.nil? }
           }
         }
end

- (Object) adjust_types(values, app = nil)



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'src/model/activeagent.rb', line 64

def adjust_types(values, app=nil)
  values = values.dup
  values.each { |key, value| 
    if(value.is_a?(Persistence::Pointer))
      values.store(key, value.resolve(app))
    else
      case(key)
      when :dose, :chemical_dose, :equivalent_dose
        begin
          values[key] = Dose.new(*value) unless(value.is_a? Dose)
        rescue(StandardError)
          values.delete(key)
        end
        if(value.nil?)
          values[key] = nil
        end
      #deprecated
      when :substance, :chemical_substance, :equivalent_substance
        if(value)
          values[key] = app.substance(value)
        end
        if(values[key].nil? && key == :substance)
          values.delete(key) 
        end
      end
    end
  }
  values
end

- (Object) checkout



21
22
23
24
25
# File 'src/model/activeagent.rb', line 21

def checkout
  if(@substance.respond_to?(:remove_sequence))
    @substance.remove_sequence(@sequence)
  end
end

- (Object) init(app)



18
19
20
# File 'src/model/activeagent.rb', line 18

def init(app)
  self.substance = app.substance(@substance_name)
end

- (Boolean) same_as?(substance_or_oid, spag = nil)

Returns:

  • (Boolean)


26
27
28
29
30
# File 'src/model/activeagent.rb', line 26

def same_as?(substance_or_oid, spag=nil)
  oid == substance_or_oid.to_i \
    ||(!@substance.nil? && @substance.same_as?(substance_or_oid) \
       && @spagyric_dose == spag)
end

- (Object) to_a



31
32
33
# File 'src/model/activeagent.rb', line 31

def to_a
  [@substance, @dose]
end

- (Object) to_s Also known as: pointer_descr



34
35
36
# File 'src/model/activeagent.rb', line 34

def to_s
  to_a.compact.join(' ')
end