Class: ODDB::Narcotic

Inherits:
Object show all
Includes:
OddbYaml, PackageObserver, Persistence
Defined in:
src/model/narcotic.rb,
ext/export/src/oddb_yaml.rb

Constant Summary

EXPORT_PROPERTIES =
[
  '@oid',
  '@substances',
]

Constants included from OddbYaml

EXPORT_PROPERTIES, YAML_URI

Constants included from Persistence

ODBA_PREDEFINE_SERIALIZABLE

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from OddbYaml

#to_yaml_properties, #to_yaml_type

Methods included from PackageObserver

#add_package, #empty?, #package_count, #remove_package

Methods included from PersistenceMethods

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

Constructor Details

- (Narcotic) initialize

A new instance of Narcotic



15
16
17
18
# File 'src/model/narcotic.rb', line 15

def initialize
  @substances = []
  super
end

Instance Attribute Details

- (Object) category

Returns the value of attribute category



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

def category
  @category
end

- (Object) reservation_text (readonly)

Returns the value of attribute reservation_text



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

def reservation_text
  @reservation_text
end

- (Object) substances (readonly)

Returns the value of attribute substances



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

def substances
  @substances
end

Instance Method Details

- (Object) add_substance(substance)



22
23
24
25
26
27
28
# File 'src/model/narcotic.rb', line 22

def add_substance(substance)
  unless(@substances.include?(substance))
    @substances.push(substance)
    @substances.odba_store
  end
  substance
end

- (Object) casrn



29
30
31
# File 'src/model/narcotic.rb', line 29

def casrn
  (subst = @substances.find do |sub| sub.casrn end) && subst.casrn
end

- (Object) checkout



32
33
34
35
36
37
38
39
40
41
42
43
# File 'src/model/narcotic.rb', line 32

def checkout
  @substances.dup.each { |sub| 
    sub.narcotic = nil 
    sub.odba_store
  }
  @substances.odba_delete
  @packages.dup.each { |pack| 
    pack.remove_narcotic(self)
    pack.odba_store 
  }
  @packages.odba_delete
end

- (Object) create_reservation_text



44
45
46
# File 'src/model/narcotic.rb', line 44

def create_reservation_text
  @reservation_text = Text::Document.new
end

- (Object) init(app = nil)



19
20
21
# File 'src/model/narcotic.rb', line 19

def init(app=nil)
  @pointer.append(@oid)
end

- (Object) pointer_descr



47
48
49
# File 'src/model/narcotic.rb', line 47

def pointer_descr
  to_s
end

- (Object) remove_substance(substance)



50
51
52
53
54
55
# File 'src/model/narcotic.rb', line 50

def remove_substance(substance)
  if(sub = @substances.delete(substance))
    @substances.odba_store
    sub
  end
end

- (Object) swissmedic_codes Also known as: swissmedic_code



56
57
58
# File 'src/model/narcotic.rb', line 56

def swissmedic_codes
  @substances.collect { |sub| sub.swissmedic_code }
end

- (Object) to_s



60
61
62
# File 'src/model/narcotic.rb', line 60

def to_s
  @substances.collect do |sub| sub.to_s end.sort.first
end

- (Object) to_yaml(opts = {})



336
337
338
339
340
341
342
343
344
345
346
# File 'ext/export/src/oddb_yaml.rb', line 336

def to_yaml( opts = {} )
  YAML::quick_emit( self.object_id, opts ) { |out|
    out.map( taguri ) { |map|
      map.add('casrn', casrn)
      to_yaml_properties.each { |m|
        map.add( m[1..-1], instance_variable_get( m ) )
      }
      map.add('packages', @packages.collect { |pac| pac.ikskey })
    }
  }
end