Class: FortIO::Namelist::Parser::ParamDef

Inherits:
Struct
  • Object
show all
Defined in:
lib/fortio-namelist/fortran_namelist.rb,
lib/fortio-namelist/fortran_namelist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#array_specObject

Returns the value of attribute array_spec

Returns:

  • (Object)

    the current value of array_spec



17
18
19
# File 'lib/fortio-namelist/fortran_namelist.rb', line 17

def array_spec
  @array_spec
end

#identObject

Returns the value of attribute ident

Returns:

  • (Object)

    the current value of ident



17
18
19
# File 'lib/fortio-namelist/fortran_namelist.rb', line 17

def ident
  @ident
end

#rvalObject

Returns the value of attribute rval

Returns:

  • (Object)

    the current value of rval



17
18
19
# File 'lib/fortio-namelist/fortran_namelist.rb', line 17

def rval
  @rval
end

Instance Method Details

#inspectObject



58
59
60
61
62
63
64
# File 'lib/fortio-namelist/fortran_namelist.rb', line 58

def inspect
  if array_spec
    return "#{ident}(#{array_spec.inspect}) = #{rval.inspect}"
  else
    return "#{ident} = #{rval}"
  end
end

#set(hash) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fortio-namelist/fortran_namelist.rb', line 21

def set (hash)
  case hash[ident]
  when Array
    case array_spec
    when nil
      if rval.is_a?(Array) and rval.size == 1
        hash[ident][0] = rval.first
      else
        hash[ident].clear
        hash[ident].push(*rval)
      end              
    else
      if array_spec.first.is_a?(Integer) 
        if rval.size == 1
          hash[ident][*array_spec] = rval.first
        else
          idx = array_spec.first
          hash[ident][idx..idx+rval.size-1] = *rval
        end
      else
        hash[ident][*array_spec] = rval
      end
    end        
  else
    if array_spec
      hash[ident] = []
      set(hash)
    else
      if rval.is_a?(Array) and rval.size == 1
        hash[ident] = rval.first
      else
        hash[ident] = rval
      end
    end
  end
end