Sha256: 94af37e86c02a4034f1197f32156aeb7ad8ee457c264c7cc12d7d85253e588fe
Contents?: true
Size: 1.48 KB
Versions: 2
Compression:
Stored size: 1.48 KB
Contents
#!/usr/bin/env ruby begin require 'linux_stat' rescue LoadError require 'bundler/setup' require 'linux_stat' end $-v = true # Print time each method takes unless --no-time or -nt option is passed MARKDOWN = ARGV.any? { |x| x[/^\-\-markdown$/] || x[/^\-md$/] } PRINT_TIME = MARKDOWN ? false : !ARGV.any? { |x| x[/^\-\-no-time$/] || x[/^\-nt$/] } %w(--markdown -md --no-time -nt).each(&ARGV.method(:delete)) # Run only desired classes / modules constants = LinuxStat.constants execute = constants.map(&:downcase).map.with_index { |x, i| constants[i] if ARGV.find { |y| y.downcase.to_sym == x } }.compact execute.replace(constants) if execute.empty? execute.sort.each do |c| e = eval("LinuxStat::#{c}") next if e.class != Module && e.class != Class meths = e.methods(false).sort if meths.length > 0 if MARKDOWN puts "### LinuxStat::#{c}\n```" else puts "\e[1;4;38;2;255;240;0mLinuxStat::#{c}\e[0m" end end meths.each do |meth| time = Time.now v = e.send(meth) time = Time.now.-(time).*(1_000_000).round(3) v = v.inspect dis = v.length > 253 ? v[0..250].strip + '...'.freeze : v if MARKDOWN puts "#{e}.#{meth}\n=> #{dis}" else puts "\e[1;38;2;80;80;255m#{e}.#{meth}\e[0m\n=> #{dis}" end puts( "(" + if time > 10_000 "\e[1;38;2;255;50;50m" elsif time > 5_000 "\e[1;38;2;255;170;0m" else "\e[1;38;2;0;170;0m" end + "Time taken: #{time}\u03BCs\e[0m)" ) if PRINT_TIME puts end puts "```\n\n" if MARKDOWN && meths.length > 0 end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
linux_stat-0.2.1 | bin/linuxstat.rb |
linux_stat-0.2.0 | bin/linuxstat.rb |