From ab55e98974b4231ae2c43ad6291ae176a9029bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20M=C3=BCller=20Madsen?= Date: Tue, 9 May 2017 12:02:15 +0200 Subject: [PATCH] improvements to code style in gen_index --- gen_index.rb | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/gen_index.rb b/gen_index.rb index 406d91b..a29e014 100644 --- a/gen_index.rb +++ b/gen_index.rb @@ -1,39 +1,33 @@ require 'erb' require 'filesize' +RES_BASE = "https://strawberry.thedevcave.net/~christoffermadsen/" +usernames = ["christoffermadsen","jmaa","jacob","alexander"] +shot_dir = "/var/shots/" erb_file = "dcav-index.erb" html_file = "/var/shots/html/index.html" class User attr_accessor :name, :count, :size - def <=> (other) + def <=> other other.count <=> count end end -RES_BASE = "https://strawberry.thedevcave.net/~christoffermadsen/" -usernames = ["christoffermadsen","jmaa","jacob","alexander"] -users = [] -shot_dir = "/var/shots/" - - +users = [] usernames.each do |username| - user = User.new - user.name = username - size = `du -B1 #{shot_dir}#{username}/ | awk {'print $1'} | head -n 1` - count = `ls -1 #{shot_dir}#{username}/ | wc -l | head -n 1` + user = User.new + user.name = username + user.size = `du -B1 #{shot_dir}#{username}/ | awk {'print $1'} | head -n 1` + .delete("\n") + .to_i + user.count = `ls -1 #{shot_dir}#{username}/ | wc -l | head -n 1` + .delete("\n") + .to_i - [size,count].each do |x| - x.delete! "\n" - end - - user.size = size.to_i - user.count = count.to_i users << user end -output = ERB.new(File.read(erb_file)).result - File.open(html_file, 'w') do |f| - f.write(output) + f << ERB.new(File.read erb_file).result end