class PBS::Torque::Attrl
Struct for Attribute C-linked list
Public Class Methods
from_list(list)
click to toggle source
Given an array of attribute names convert it to {Attrl} C-linked list @param list [Array<Symbol>] list of attribute names @return [Attrl] generated attribute c-linked list object
# File lib/pbs/torque.rb, line 214 def self.from_list(list) attrl = nil prev = Attrl.new(FFI::Pointer::NULL) list.each do |key| attrl = Attrl.new attrl[:name] = FFI::MemoryPointer.from_string(key.to_s) attrl[:next] = prev prev = attrl end attrl end
Public Instance Methods
to_h()
click to toggle source
Convert to hash describing this linked list @return [Hash] hash describing linked list
# File lib/pbs/torque.rb, line 228 def to_h attrl = self hash = {} until attrl.to_ptr.null? n = attrl[:name].read_string v = attrl[:value].read_string r = attrl[:resource].null? ? nil : attrl[:resource].read_string r ? (hash[n.to_sym] ||= {} and hash[n.to_sym][r.to_sym] = v) : hash[n.to_sym] = v attrl = attrl[:next] end hash end