speedometer 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/speedometer.rb +65 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9b0d26cabc578b07713143c4c2c6eacebcaf484b
4
+ data.tar.gz: da50f1ed3249199cb6ae72a1344d99421759329f
5
+ SHA512:
6
+ metadata.gz: 904e95db1760d659a693bd67851a65067da884911406e9d0cbe806416ad0d683b8f0d626293ece5b1d7b6bb46177378a62387beaa8bc3f926b99408510ef365d
7
+ data.tar.gz: b7952c136ad183abd984a86f5ffc541a69627335e7531f5f609e06d981f19cf539f292eee6e925450e81ae380a0ee61725338e915ada444733e47cdbe6c566da
@@ -0,0 +1,65 @@
1
+ ########################################################################
2
+ # speedometer - class to track, calculate and display upload speed from an application
3
+ # Copyright (c) 2013, Tadeus Dobrovolskij
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License along
15
+ # with this program; if not, write to the Free Software Foundation, Inc.,
16
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
+ ########################################################################
18
+ # = Methods
19
+ # * new - accepts units in KB/MB/GB
20
+ # * display - displays upload speed
21
+ # * log(message) - you need to use this instead of puts
22
+ ########################################################################
23
+ class Speedometer
24
+
25
+ attr_accessor :uploaded, :refresh_time, :active
26
+
27
+ def initialize(units="MB")
28
+ @start_time = Time.now
29
+ @active = true
30
+ @refresh_time = 1000
31
+ if ["KB","MB","GB"].include?(units)
32
+ @units = units
33
+ else
34
+ @units = "MB"
35
+ end
36
+ end
37
+
38
+ def clear
39
+ length = `stty`
40
+ length = length.split.last.to_i
41
+ print "\r"
42
+ print "#{' ' * length}"
43
+ print "\r"
44
+ end
45
+
46
+ def display
47
+ clear
48
+ time = Time.now
49
+ speed = (uploaded.to_f / (time - @start_time)) / 1024
50
+ if @units == "MB" or @units == "GB"
51
+ speed = speed / 1024
52
+ end
53
+ if @units == "GB"
54
+ speed = speed / 1024
55
+ end
56
+ print "#{speed.round(2)}#{@units}/s"
57
+ sleep @refresh_time.to_f / 1000
58
+ end
59
+
60
+ def log(msg)
61
+ clear
62
+ puts msg
63
+ display
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: speedometer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tadeus Dobrovolskij
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Library to track and display bandwith usage inside the application
14
+ email: root@tad-do.net
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/speedometer.rb
20
+ homepage: https://github.com/tdobrovolskij/speedometer
21
+ licenses:
22
+ - GPLv2
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.0.3
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: speedometer
44
+ test_files: []