I've tried and tried, but I can't make this less ugly/more ruby-like. It seems like there just must be a better way. Help me learn.
class Df
attr_accessor :thresh
attr_reader :dfo
def initialize
@dfo = []
@df = '/opt/TWWfsw/bin/gdf'
case RUBY_PLATFORM
when /hpux/i
@fstyp = 'vxfs'
when /solaris/i
# fix: need /tmp too
@fstyp = 'ufs'
when /linux/i
@df = '/bin/df'
@fstyp = 'ext3'
end
@dfo = parsedf
end
def parsedf
ldf = []
[" "," -i"] .each do |arg|
fields = %w{device size used avail capp mount}
fields = %w{device inodes inodesused inodesavail iusep mount} if arg == ' -i'
ldf.push %x{#{@df} -P -t #{@fstyp}#{arg}}.split(/\n/)[1..-1].collect{|line| Hash[*fields.zip(line.split).flatten]}
end
out = []
# surely there must be an easier way
ldf[0].each do |x|
ldf[1].select { |y|
if y['device'] == x['device']
out.push x.merge(y)
end
}
end
out
end
end