Class: Bio::FlatFileIndex::FileIDs

Inherits:
Array
  • Object
show all
Defined in:
lib/bio/io/flatfile/index.rb

Overview

FileIDs class.

Internal use only.

Instance Method Summary collapse

Constructor Details

#initialize(prefix, hash) ⇒ FileIDs

Returns a new instance of FileIDs.



572
573
574
575
# File 'lib/bio/io/flatfile/index.rb', line 572

def initialize(prefix, hash)
  @hash = hash
  @prefix = prefix
end

Instance Method Details

#[](n) ⇒ Object



577
578
579
580
581
582
583
584
585
586
587
588
# File 'lib/bio/io/flatfile/index.rb', line 577

def [](n)
  r = super(n)
  if r then
    r
  else
    data = @hash["#{@prefix}#{n}"]
    if data then
      self[n] = data
    end
    super(n)
  end
end

#[]=(n, data) ⇒ Object



590
591
592
593
594
595
596
597
598
599
600
# File 'lib/bio/io/flatfile/index.rb', line 590

def []=(n, data)
  if data.is_a?(FileID) then
    super(n, data)
  elsif data then
    super(n, FileID.new_from_string(data))
  else
    # data is nil
    super(n, nil)
  end
  self[n]
end

#add(*arg) ⇒ Object



602
603
604
605
606
# File 'lib/bio/io/flatfile/index.rb', line 602

def add(*arg)
  arg.each do |filename|
    self << FileID.new(filename)
  end
end

#cache_allObject



608
609
610
611
612
613
614
615
616
617
618
619
620
621
# File 'lib/bio/io/flatfile/index.rb', line 608

def cache_all
  a = @hash.keys.collect do |k|
    if k =~ /\A#{Regexp.escape(@prefix)}(\d+)/ then
      $1.to_i
    else
      nil
    end
  end
  a.compact!
  a.each do |i|
    self[i]
  end
  a
end

#check_allObject Also known as: check



657
658
659
660
661
662
663
664
665
# File 'lib/bio/io/flatfile/index.rb', line 657

def check_all
  self.cache_all
  r = true
  self.each do |x|
    r = x.check
    break unless r
  end
  r
end

#close_allObject Also known as: close



668
669
670
671
672
673
# File 'lib/bio/io/flatfile/index.rb', line 668

def close_all
  self.each do |x|
    x.close
  end
  nil
end

#eachObject



623
624
625
626
627
628
629
# File 'lib/bio/io/flatfile/index.rb', line 623

def each
  (0...self.size).each do |i|
    x = self[i]
    yield(x) if x
  end
  self
end

#each_with_indexObject



631
632
633
634
635
636
637
# File 'lib/bio/io/flatfile/index.rb', line 631

def each_with_index
  (0...self.size).each do |i|
    x = self[i]
    yield(x, i) if x
  end
  self
end

#filenamesObject



648
649
650
651
652
653
654
655
# File 'lib/bio/io/flatfile/index.rb', line 648

def filenames
  self.cache_all
  a = []
  self.each do |x|
    a << x.filename
  end
  a
end

#keysObject



639
640
641
642
643
644
645
646
# File 'lib/bio/io/flatfile/index.rb', line 639

def keys
  self.cache_all
  a = []
  (0...self.size).each do |i|
    a << i if self[i]
  end
  a
end

#recalc_allObject Also known as: recalc



676
677
678
679
680
681
682
# File 'lib/bio/io/flatfile/index.rb', line 676

def recalc_all
  self.cache_all
  self.each do |x|
    x.recalc
  end
  true
end