Class: NumRu::AttributeNetCDF

Inherits:
Object
  • Object
show all
Defined in:
lib/numru/gphys/attributenetcdf.rb

Instance Method Summary collapse

Constructor Details

#initialize(ncvar) ⇒ AttributeNetCDF

Returns a new instance of AttributeNetCDF.

Raises:

  • (TypeError)


13
14
15
16
17
18
# File 'lib/numru/gphys/attributenetcdf.rb', line 13

def initialize( ncvar )
   raise TypeError unless NetCDFVar===ncvar || NetCDF===ncvar
   @nv = ncvar
   convention = NetCDF_Conventions.find(ncvar.file)
   extend( convention::Attribute_Mixin )
end

Instance Method Details

#[](name) ⇒ Object



20
21
22
# File 'lib/numru/gphys/attributenetcdf.rb', line 20

def [](name)
    ( att = @nv.att(name) ) ? att.get : att
end

#[]=(name, val) ⇒ Object



24
25
26
27
# File 'lib/numru/gphys/attributenetcdf.rb', line 24

def []=(name, val)
   @nv.put_att(name,val)
   val
end

#copy(to = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/numru/gphys/attributenetcdf.rb', line 29

def copy(to=nil)
   # deep copy (clone), or addition to "to" if given.
   # ATTENTION!  If the destination "to" is not given, it will
   # be an Attribute (not AttributeNetCDF), which is on memory.
   if to == nil
      to = NumRu::Attribute.new
   end
   self.each{|key, val|
      to[key] = val
   }
   to
end

#delete(key) ⇒ Object



64
65
66
# File 'lib/numru/gphys/attributenetcdf.rb', line 64

def delete(key)
   @nv.att(key).delete
end

#delete_ifObject



68
69
70
# File 'lib/numru/gphys/attributenetcdf.rb', line 68

def delete_if
   each{|key,val| delete(key) if yield(key,val)}
end

#eachObject



48
49
50
# File 'lib/numru/gphys/attributenetcdf.rb', line 48

def each
   @nv.each_att{|att| yield(att.name, att.get)}
end

#each_keyObject



52
53
54
# File 'lib/numru/gphys/attributenetcdf.rb', line 52

def each_key
   @nv.each_att{|att| yield(att.name)}
end

#has_key?(key) ⇒ Boolean Also known as: include?, key?

Returns:

  • (Boolean)


72
73
74
# File 'lib/numru/gphys/attributenetcdf.rb', line 72

def has_key?(key)
   @nv.att(key) ? true : false
end

#keysObject



60
61
62
# File 'lib/numru/gphys/attributenetcdf.rb', line 60

def keys
   @nv.att_names
end

#lengthObject



56
57
58
# File 'lib/numru/gphys/attributenetcdf.rb', line 56

def length
   @nv.natts
end

#rename(key_from, key_to) ⇒ Object



42
43
44
45
46
# File 'lib/numru/gphys/attributenetcdf.rb', line 42

def rename(key_from, key_to)
   att = @nv.att(key_from)
   if att==nil; raise "attribute #{key_from} does not exist"; end
   att.name= key_to
end