graph-ruby 0.0.0
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.
- checksums.yaml +7 -0
- data/lib/graph-ruby.rb +99 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d0b7f3fb2ccd309786bb71f49d33cf6a246fb62c
|
4
|
+
data.tar.gz: d422ff3bc7ebbc6c2e7c4b0de0e37d9aa5a7024f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cb25fd3ca243b5cae5cd04447fabfc489f8fe7305696ba3992b5b898bc4755c23e2e7ba1aaa33f272815421c59b1c0909e061fdb7f22b6fcf9034ea2da297583
|
7
|
+
data.tar.gz: ef5f15ff6f6909d5aa5da98a26802075b452af806ec483b7cd0243efd2977b994faaa6694a9dd029a2fcd81f114d6c80225896020300f1cac77331ec2ddfb798
|
data/lib/graph-ruby.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
class GraphRuby
|
2
|
+
|
3
|
+
def self.histogram(data)
|
4
|
+
Histogram.new(data)
|
5
|
+
end
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
# my_hash = {a: 5, b: 6, c: 10, d: 2, e: 9}
|
11
|
+
|
12
|
+
|
13
|
+
class Histogram
|
14
|
+
def initialize(my_hash = {}, axis = 1)
|
15
|
+
@data = my_hash
|
16
|
+
@axis = axis
|
17
|
+
run
|
18
|
+
end
|
19
|
+
|
20
|
+
def run
|
21
|
+
clear_screen
|
22
|
+
calculate_padding
|
23
|
+
print_heading
|
24
|
+
print_value
|
25
|
+
# convert_to_percentages
|
26
|
+
# calculate_axis
|
27
|
+
print_values
|
28
|
+
end
|
29
|
+
|
30
|
+
def clear_screen
|
31
|
+
puts "\e[H\e[2J"
|
32
|
+
end
|
33
|
+
|
34
|
+
def print_heading
|
35
|
+
@data.each do |key, value|
|
36
|
+
print "%-#{@padding}s" % "#{key}"
|
37
|
+
end
|
38
|
+
puts ""
|
39
|
+
puts "-"*((@data.length*@padding)-3)
|
40
|
+
end
|
41
|
+
|
42
|
+
def print_value
|
43
|
+
@data.each do |key, value|
|
44
|
+
print "%-#{@padding}s" % "#{value}"
|
45
|
+
end
|
46
|
+
puts ""
|
47
|
+
end
|
48
|
+
|
49
|
+
def calculate_axis
|
50
|
+
@data.each {|key, value| @data[key] = value}
|
51
|
+
end
|
52
|
+
|
53
|
+
def convert_to_percentages
|
54
|
+
sum = calculate_sum
|
55
|
+
|
56
|
+
@data.each do |key, value|
|
57
|
+
@data[key] = ((value.to_f)/(sum.to_f)*100).to_i
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def calculate_sum
|
62
|
+
sum = 0
|
63
|
+
@data.each do |key, value|
|
64
|
+
sum += value
|
65
|
+
end
|
66
|
+
return sum
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def print_values
|
71
|
+
all_zero = false
|
72
|
+
while !all_zero
|
73
|
+
all_zero = true
|
74
|
+
@data.each do |key, value|
|
75
|
+
if value > 0
|
76
|
+
print print "%-#{@padding}s" % "X"
|
77
|
+
@data[key] -=1
|
78
|
+
all_zero = false
|
79
|
+
else
|
80
|
+
print "%-#{@padding}s" % " "
|
81
|
+
end
|
82
|
+
end
|
83
|
+
puts " "
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
def calculate_padding
|
89
|
+
longest_length_sf = 0
|
90
|
+
@data.each do |key, value|
|
91
|
+
longest_length_sf = key.length if key.length > longest_length_sf
|
92
|
+
end
|
93
|
+
|
94
|
+
@padding = longest_length_sf + 3
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: graph-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Amelia Downs
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: 'This tool allows you to graph things with ONLY ruby. No javascript,
|
14
|
+
no webpage. Nothing. It only uses the terminal. '
|
15
|
+
email: downs.amelia@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/graph-ruby.rb
|
21
|
+
homepage: ''
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.4.1
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Graph ruby data in the terminal
|
45
|
+
test_files: []
|