module Mspire::Obo::HashProvider
requires classes to provide the :stanzas method
Attributes
id_to_cast[R]
id_to_name[R]
id_to_stanza[R]
name_to_id[R]
Public Instance Methods
build_hash(key,val)
click to toggle source
if val is a symbol, will call that method on the stanza
# File lib/mspire/obo/hash_provider.rb, line 94 def build_hash(key,val) hash = {} stanzas.each do |el| tv = el.tagvalues case val when nil hash[tv[key].first] = el when Symbol hash[tv[key].first] = (el.send(val)) else hash[tv[key].first] = tv[val].first end end hash end
cast(id, val=nil)
click to toggle source
requires id_to_cast
! be called first. If no val given, returns a symbol (e.g., :to_f). If given a val, then it returns the cast of that val.
# File lib/mspire/obo/hash_provider.rb, line 71 def cast(id, val=nil) val ? val.send(@id_to_cast[id]) : @id_to_cast[id] end
id_to_cast!()
click to toggle source
makes and sets the id_to_cast
hash
# File lib/mspire/obo/hash_provider.rb, line 65 def id_to_cast! @id_to_cast = make_id_to_cast self end
id_to_name!()
click to toggle source
builds the id_to_name
hash and returns self for chaining
# File lib/mspire/obo/hash_provider.rb, line 46 def id_to_name! @id_to_name = make_id_to_name self end
id_to_stanza!()
click to toggle source
makes and sets the id_to_stanza
hash and returns self
# File lib/mspire/obo/hash_provider.rb, line 26 def id_to_stanza! @id_to_stanza = make_id_to_stanza self end
make_all!()
click to toggle source
builds all hashes for fast access
# File lib/mspire/obo/hash_provider.rb, line 12 def make_all! id_to_name!.id_to_cast!.id_to_stanza!.name_to_id! end
make_id_to_cast()
click to toggle source
ID TO CAST
# File lib/mspire/obo/hash_provider.rb, line 60 def make_id_to_cast build_hash('id', :cast_method) end
make_id_to_name()
click to toggle source
returns an id to name Hash
# File lib/mspire/obo/hash_provider.rb, line 41 def make_id_to_name build_hash('id', 'name') end
make_id_to_stanza()
click to toggle source
returns an id_to_stanza
hash
# File lib/mspire/obo/hash_provider.rb, line 21 def make_id_to_stanza build_hash('id', nil) end
make_name_to_id()
click to toggle source
returns a name_to_id
Hash
# File lib/mspire/obo/hash_provider.rb, line 86 def make_name_to_id build_hash('name', 'id') end
name(id)
click to toggle source
requires id_to_name
! be called first
# File lib/mspire/obo/hash_provider.rb, line 52 def name(id) @id_to_name[id] end
name_to_id!()
click to toggle source
makes and sets the name_to_id
hash and returns self
# File lib/mspire/obo/hash_provider.rb, line 80 def name_to_id! @name_to_id = make_name_to_id self end
stanza(id)
click to toggle source
returns an Obo::Stanza
object
# File lib/mspire/obo/hash_provider.rb, line 32 def stanza(id) @id_to_stanza[id] end