Class: ODDB::Drugs::Part

Inherits:
Model
  • Object
show all
Defined in:
lib/oddb/drugs/part.rb

Constant Summary

Constants included from OddbUri

OddbUri::YAML_URI

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#__odba_delete__, #__odba_save__, _serializables, belongs_to, connections, connector, connectors, #data_origin, #data_origins, delegates, #delete, find_by_uid, has_many, is_coded, m10l_document, multilingual, #odba_serializables, #oid, on_delete, on_save, predicates, #save, #saved?, serializables, serialize, singular

Methods included from ODBA::Persistable

#to_yaml_properties

Methods included from Yaml

append_features, #to_yaml_properties

Methods included from OddbUri

#to_yaml, #to_yaml_map, #to_yaml_type

Constructor Details

#initializePart

Returns a new instance of Part.



21
22
23
24
# File 'lib/oddb/drugs/part.rb', line 21

def initialize
  super
  @size = 1
end

Instance Attribute Details

#multiObject

A partial package can be described as e.g.

10 x 5 Ampoules of 20 ml 
 ^----------------------- :multi    - Numeric
     ^------------------- :size     - Numeric
            ^------------ :unit     - Unit (a multilingual)
                    ^---- :quantity - Dose


19
20
21
# File 'lib/oddb/drugs/part.rb', line 19

def multi
  @multi
end

#quantityObject

A partial package can be described as e.g.

10 x 5 Ampoules of 20 ml 
 ^----------------------- :multi    - Numeric
     ^------------------- :size     - Numeric
            ^------------ :unit     - Unit (a multilingual)
                    ^---- :quantity - Dose


19
20
21
# File 'lib/oddb/drugs/part.rb', line 19

def quantity
  @quantity
end

#sizeObject

Returns the value of attribute size.



20
21
22
# File 'lib/oddb/drugs/part.rb', line 20

def size
  @size
end

#unitObject

A partial package can be described as e.g.

10 x 5 Ampoules of 20 ml 
 ^----------------------- :multi    - Numeric
     ^------------------- :size     - Numeric
            ^------------ :unit     - Unit (a multilingual)
                    ^---- :quantity - Dose


19
20
21
# File 'lib/oddb/drugs/part.rb', line 19

def unit
  @unit
end

Instance Method Details

#comparable_sizeObject



25
26
27
# File 'lib/oddb/drugs/part.rb', line 25

def comparable_size
  (@quantity || Dose.new(1)) * (@size || 1) * (@multi || 1)
end

#to_s(language = :de) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/oddb/drugs/part.rb', line 36

def to_s(language=:de)
  parts = []
  multi = @multi.to_i
  if(multi > 1)
    parts.push multi, 'x'
  end
  size = @size.to_i
  if(size > 1)
    parts.push(size)
  end
  if(unit = @unit)
    parts.push(unit.name.send(language))
  end
  if(quantity = @quantity)
    parts.push 'à', quantity
  end
  parts.join(' ')
end