Class: ODDB::ReadonlyServer

Inherits:
Object show all
Defined in:
ext/readonly/src/readonly_server.rb

Instance Method Summary collapse

Instance Method Details

#get_currency_rate(symbol) ⇒ Object



7
8
9
# File 'ext/readonly/src/readonly_server.rb', line 7

def get_currency_rate(symbol)
  ODDB::Currency.rate('CHF', symbol)
end

#remote_comparables(package) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'ext/readonly/src/readonly_server.rb', line 10

def remote_comparables(package)
  package = ODDB::Remote::Package.new(package)
  sequence = package.sequence
  comparables = []
  atcs = ODBA.cache.retrieve_from_index('atc_index', sequence.atc_code)
  if(atcs.size == 1 && atc = atcs.first)
    atc.sequences.each { |seq|
      if(sequence.comparable?(seq))
        comparables.concat seq.packages.values.select { |pac|
          package.comparable?(pac)
        }
      end
    }
  end
  ODBA::DRbWrapper.new comparables
end

#remote_each_atc_class(&block) ⇒ Object



26
27
28
29
30
# File 'ext/readonly/src/readonly_server.rb', line 26

def remote_each_atc_class(&block)
  ODDB::AtcClass.odba_extent do |atc|
    block.call ODBA::DRbWrapper.new(atc)
  end
end

#remote_each_company(&block) ⇒ Object

for migration to ch.oddb.org



31
32
33
34
35
36
# File 'ext/readonly/src/readonly_server.rb', line 31

def remote_each_company(&block) # for migration to ch.oddb.org
  ODDB::Company.odba_extent.each do |comp|
    block.call ODBA::DRbWrapper.new(comp)
  end
  nil # don't try to pass all registrations across DRb-Land
end

#remote_each_package(&block) ⇒ Object



37
38
39
40
41
42
43
44
# File 'ext/readonly/src/readonly_server.rb', line 37

def remote_each_package(&block)
  ODDB::Package.odba_extent.each do |pac|
    if(pac.public? && !pac.narcotic?)
      block.call ODBA::DRbWrapper.new(pac)
    end
  end
  nil # don't try to pass all registrations across DRb-Land
end

#remote_export(name) ⇒ Object



45
46
47
48
49
# File 'ext/readonly/src/readonly_server.rb', line 45

def remote_export(name)
  ODDB::Exporter.new(self).export_helper(name) { |path|
    yield path
  }
end

#remote_packages(query) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'ext/readonly/src/readonly_server.rb', line 50

def remote_packages(query)
seqs = ODBA.cache.retrieve_from_index('sequence_index_exact', query)
  if(seqs.empty?)
    seqs = ODBA.cache.\
      retrieve_from_index('substance_index_sequence', query)
  end
  ODBA::DRbWrapper.new seqs.collect { |seq|
    seq.public_packages
  }.flatten
end