Class: NumRu::Gtool3TimeVal

Inherits:
Object
  • Object
show all
Includes:
IndexMixin
Defined in:
lib/numru/gphys/gtool3.rb

Overview

Behave like a NArray (by using method_missing)

Constant Summary collapse

@@na_methods =

Hash for fast lookup

Hash.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from IndexMixin

#gen_idx, #range_negproc, #rubber_expansion, #slicer2idx, #slicer_len, #slicer_minmax, #slicer_negproc

Constructor Details

#initialize(len, file, delimlen, timblen) ⇒ Gtool3TimeVal

Returns a new instance of Gtool3TimeVal.



652
653
654
655
656
657
658
# File 'lib/numru/gphys/gtool3.rb', line 652

def initialize(len, file, delimlen, timblen)
  @length = len
  @boffset = 24*Gtool3::FLDLEN + delimlen
  @timeblen = timblen
  @file = file
  @val = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



692
693
694
695
696
697
698
# File 'lib/numru/gphys/gtool3.rb', line 692

def method_missing(name, *args)
  if @@na_methods[name]
    get.__send__(name, *args)
  else
    super(name, *args)
  end
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



660
661
662
# File 'lib/numru/gphys/gtool3.rb', line 660

def file
  @file
end

#lengthObject (readonly)

Returns the value of attribute length.



660
661
662
# File 'lib/numru/gphys/gtool3.rb', line 660

def length
  @length
end

Instance Method Details

#[](arg) ⇒ Object



676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
# File 'lib/numru/gphys/gtool3.rb', line 676

def [](arg)
  sl = slicer2idx(arg,@length)
  if @val.nil? && sl.length <= @length/20 
    # if the request is only for a small portion, it would 
    # be better just read it, rather than to put data in cache.
    val = NArray.float(@length)
    for i in sl
      @file.seek( @boffset + i*@timeblen )
      val[i] = @file.read(Gtool3::FLDLEN).to_i
    end
    val
  else
    get[sl]
  end
end

#getObject



662
663
664
665
666
667
668
669
670
671
# File 'lib/numru/gphys/gtool3.rb', line 662

def get
  if @val.nil?
    @val = NArray.float(@length)
    for i in 0...@length
      @file.seek( @boffset + i*@timeblen )
      @val[i] = @file.read(Gtool3::FLDLEN).to_i
    end
  end
  @val
end