Class: PBS::Torque::Attropl

Inherits:
FFI::Struct
  • Object
show all
Defined in:
lib/pbs/torque.rb

Overview

Struct for Attribute Operation C-linked list

Class Method Summary collapse

Class Method Details

.from_hash(hash) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/pbs/torque.rb', line 125

def self.from_hash(hash)
  # Convert hash into array
  # Format: {name: value, name: {resource: value, resource: value}}
  # {a: 1, b: {c: 2, d: 3}} => [[:a,1],[:b,2,:c],[:b,3,:d]]
  ary = hash.map{|k,v| [*v].map{|v2| [k,*[*v2].reverse]}}.flatten(1)
  attropl = nil
  prev = Attropl.new(FFI::Pointer::NULL)
  ary.each do |attrib|
    attropl = Attropl.new
    attropl[:name] = FFI::MemoryPointer.from_string(attrib[0].to_s)
    attropl[:value] = FFI::MemoryPointer.from_string(attrib[1])
    attropl[:resource] = FFI::MemoryPointer.from_string(attrib[2].to_s) unless attrib[2].nil?
    attropl[:op] = 0
    attropl[:next] = prev
    prev = attropl
  end
  attropl
end