Class: BELParser::Resource::ResourceURLReader

Inherits:
Object
  • Object
show all
Includes:
Reader
Defined in:
lib/bel_parser/resource/resource_url_reader.rb

Overview

ResourceURLReader retrieves datasets and values from Annotation (i.e. belanno extension) and Namespace (i.e. belns extension) files. Value and encoding are stored in DBM database files to reduce the runtime memory usage (22 resources loaded, totaling 100MB memory usage).

Only supports resource identifiers with an HTTP or HTTPS scheme.

Instance Method Summary collapse

Methods included from Reader

assert_reader

Constructor Details

#initialize(reuse_database_files = true) ⇒ ResourceURLReader

Parameters:

  • reuse_database_files (Boolean) (defaults to: true)

    specify true to reuse database files; false to create new database files (default)



33
34
35
36
37
# File 'lib/bel_parser/resource/resource_url_reader.rb', line 33

def initialize(reuse_database_files = true)
  @resources = {}
  @datasets  = ResourceURLReader.open_datasets_file
  @reuse     = reuse_database_files
end

Instance Method Details

#retrieve_resource(resource_identifier) ⇒ FileResource

Retrieve the resource identified by resource_identifier.

Parameters:

  • resource_identifier (String)

    the resource identifier

Returns:



43
44
45
46
47
# File 'lib/bel_parser/resource/resource_url_reader.rb', line 43

def retrieve_resource(resource_identifier)
  dataset = read_resource(resource_identifier)[:dataset]
  return nil if dataset.types.all?(&:nil?)
  dataset
end

#retrieve_value_from_resource(resource_identifier, value) ⇒ Object



49
50
51
52
53
54
# File 'lib/bel_parser/resource/resource_url_reader.rb', line 49

def retrieve_value_from_resource(resource_identifier, value)
  resource = read_resource(resource_identifier)
  encoding = resource[:values][value]
  return nil unless encoding
  [FileResourceValue.new(resource[:dataset], value, encoding)]
end

#retrieve_values_from_resource(resource_identifier) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/bel_parser/resource/resource_url_reader.rb', line 56

def retrieve_values_from_resource(resource_identifier)
  resource = read_resource(resource_identifier)
  dataset  = resource[:dataset]
  return nil if resource[:values].size.zero?
  resource[:values].lazy.map do |value, encoding|
    FileResourceValue.new(dataset, value, encoding)
  end
end