Class: Bio::FlatFileIndex::NameSpaces

Inherits:
Hash show all
Defined in:
lib/bio/io/flatfile/index.rb

Overview

namespaces

Internal use only.

Instance Method Summary collapse

Constructor Details

#initialize(dbname, nsclass, arg) ⇒ NameSpaces

Returns a new instance of NameSpaces.



1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
# File 'lib/bio/io/flatfile/index.rb', line 1056

def initialize(dbname, nsclass, arg)
  @dbname = dbname
  @nsclass = nsclass
  if arg.is_a?(String) then
    a = arg.split("\t")
  else
    a = arg
  end
  a.each do |x|
    self[x] = @nsclass.new(@dbname, x)
  end
  self
end

Instance Method Details

#close_allObject Also known as: close



1086
1087
1088
# File 'lib/bio/io/flatfile/index.rb', line 1086

def close_all
  values.each { |x| x.file.close }
end

#each_filesObject



1076
1077
1078
1079
1080
# File 'lib/bio/io/flatfile/index.rb', line 1076

def each_files
  self.values.each do |x|
    yield x
  end
end

#each_namesObject



1070
1071
1072
1073
1074
# File 'lib/bio/io/flatfile/index.rb', line 1070

def each_names
  self.names.each do |x|
    yield x
  end
end

#namesObject



1082
1083
1084
# File 'lib/bio/io/flatfile/index.rb', line 1082

def names
  keys
end

#search(key) ⇒ Object



1091
1092
1093
1094
1095
1096
1097
1098
1099
# File 'lib/bio/io/flatfile/index.rb', line 1091

def search(key)
  r = []
  values.each do |ns|
    r.concat ns.search(key)
  end
  r.sort!
  r.uniq!
  r
end

#search_names(key, *names) ⇒ Object



1101
1102
1103
1104
1105
1106
1107
1108
1109
# File 'lib/bio/io/flatfile/index.rb', line 1101

def search_names(key, *names)
  r = []
  names.each do |x|
    ns = self[x]
    raise "undefined namespace #{x.inspect}" unless ns
    r.concat ns.search(key)
  end
  r
end

#to_sObject



1111
1112
1113
# File 'lib/bio/io/flatfile/index.rb', line 1111

def to_s
  names.join("\t")
end