Class: ODDB::MedData::DRbSession

Inherits:
Object
  • Object
show all
Includes:
DRb::DRbUndumped
Defined in:
ext/meddata/src/drbsession.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (DRbSession) initialize(search_type)

A new instance of DRbSession



12
13
14
15
# File 'ext/meddata/src/drbsession.rb', line 12

def initialize(search_type)
  @search_type = search_type
  @session = Session.new(search_type)
end

Instance Attribute Details

- (Object) search_type (readonly)

Returns the value of attribute search_type



11
12
13
# File 'ext/meddata/src/drbsession.rb', line 11

def search_type
  @search_type
end

Instance Method Details

- (Object) _dispatch(results, &block)



42
43
44
45
46
47
48
49
50
51
52
53
# File 'ext/meddata/src/drbsession.rb', line 42

def _dispatch(results, &block)
  if(block_given?)
    results.each { |ctl, values|
      block.call(Result.new(values, ctl))
    }
    nil
  else
    results.collect { |ctl, values|
      Result.new(values, ctl)
    }
  end
end

- (Object) detail(result, template)



16
17
18
19
20
21
22
23
24
# File 'ext/meddata/src/drbsession.rb', line 16

def detail(result, template)
  html = @session.detail_html(result.ctl)
  writer = DetailWriter.new
  formatter = Formatter.new(writer)
  parser = HtmlParser.new(formatter)
  parser.feed(html)
  results = writer.extract_data(template)
  remove_whitespace(results)
end

- (Object) remove_whitespace(data)



25
26
27
28
29
# File 'ext/meddata/src/drbsession.rb', line 25

def remove_whitespace(data)
  data.each { |key, value|
    value.gsub!(/\302\240/, "") unless(value.nil?)
  }
end

- (Object) search(criteria, &block)



30
31
32
33
34
35
36
37
38
39
40
41
# File 'ext/meddata/src/drbsession.rb', line 30

def search(criteria, &block)
  html = @session.get_result_list(criteria)
  if(html.include?('lblcountPreciseSearch'))
    raise OverflowError, 'not all valid entries in result!'
  end
  writer = ResultWriter.new(@search_type)
  formatter = Formatter.new(writer)
  parser = HtmlParser.new(formatter)
  parser.feed(html)
  results = writer.extract_data
  _dispatch(results, &block)
end