Class: NumRu::AttributeNetCDF
- Inherits:
-
Object
- Object
- NumRu::AttributeNetCDF
- Defined in:
- lib/numru/gphys/attributenetcdf.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, val) ⇒ Object
- #copy(to = nil) ⇒ Object
- #delete(key) ⇒ Object
- #delete_if ⇒ Object
- #each ⇒ Object
- #each_key ⇒ Object
- #has_key?(key) ⇒ Boolean (also: #include?, #key?)
-
#initialize(ncvar) ⇒ AttributeNetCDF
constructor
A new instance of AttributeNetCDF.
- #keys ⇒ Object
- #length ⇒ Object
- #rename(key_from, key_to) ⇒ Object
Constructor Details
#initialize(ncvar) ⇒ AttributeNetCDF
Returns a new instance of AttributeNetCDF.
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_if ⇒ Object
68 69 70 |
# File 'lib/numru/gphys/attributenetcdf.rb', line 68 def delete_if each{|key,val| delete(key) if yield(key,val)} end |
#each ⇒ Object
48 49 50 |
# File 'lib/numru/gphys/attributenetcdf.rb', line 48 def each @nv.each_att{|att| yield(att.name, att.get)} end |
#each_key ⇒ Object
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?
72 73 74 |
# File 'lib/numru/gphys/attributenetcdf.rb', line 72 def has_key?(key) @nv.att(key) ? true : false end |
#keys ⇒ Object
60 61 62 |
# File 'lib/numru/gphys/attributenetcdf.rb', line 60 def keys @nv.att_names end |
#length ⇒ Object
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 |