graph-bar 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graph/bar.rb +58 -4
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 417c77b427629d056a1bbfdfb8bbd9ec4963f010
4
- data.tar.gz: f575466a80884b49c937382983823c06772071ad
3
+ metadata.gz: a5e58d816cf6b97833708fad489ee513ece24388
4
+ data.tar.gz: 9c92fc97fa846b3d2cefa165b5104f74214c7523
5
5
  SHA512:
6
- metadata.gz: 8f6f38147b552f94dc49dfdc5bbcd88e6d9aef726616b32353e2c2f358093c00548b0fc772ae3072a09be186d7dc02a5a50d2b4af8c1e117856fd75445c5c0c1
7
- data.tar.gz: 7df7964c02ccc0d47402961a976c934de3b5be3da12b88c243404bec705b3894d9b20e2af51c15e878d363e4331eb841ec8b59420e0e496c650875bda36915db
6
+ metadata.gz: e36232e0331f6382215f5a90a0ea01dbff1cde19072b9d5b15a7327e2bfa6c05ee36014619d96f61c3dcc93c3c1b6a678da0081d27dabf648f36e0127acb8967
7
+ data.tar.gz: c62e2fa6d85dcbd59eba878f771be744b7ec767f36e225e69090cc0f7d29f431031d1eccf3b6c166c4cb3b044714124eb9f4dc47b8cc3f3dfd8a7e2b6dad5f3b
data/lib/graph/bar.rb CHANGED
@@ -2,6 +2,19 @@
2
2
  # This module contains tools for analyzing and graphing data arrays
3
3
  #
4
4
  module Graph
5
+ ##
6
+ # Modes for printing the graph
7
+ #
8
+ module PrintMode
9
+ ##
10
+ # No scale factor
11
+ #
12
+ NOSCALE = 1
13
+ ##
14
+ # Manually set scale factor
15
+ #
16
+ SCALE = 2
17
+ end
5
18
  ##
6
19
  # This class allows the display of data arrays in bar graph format
7
20
  #
@@ -10,7 +23,9 @@ module Graph
10
23
  # Allows optionally setting the initial dataset as a parameter
11
24
  #
12
25
  def initialize(data = nil)
13
- @data = data
26
+ data(data)
27
+ mode(PrintMode::NOSCALE)
28
+ scale(1)
14
29
  end
15
30
 
16
31
  ##
@@ -22,11 +37,50 @@ module Graph
22
37
  end
23
38
 
24
39
  ##
25
- # Print the bar graph to stdout
40
+ # Get or Set the print mode
41
+ #
42
+ def mode(mode = nil)
43
+ @mode = mode unless mode.nil?
44
+ @mode
45
+ end
46
+
47
+ ##
48
+ # Get or Set th print scale
49
+ #
50
+ def scale(scale = nil)
51
+ @scale = scale unless scale.nil?
52
+ @scale
53
+ end
54
+
55
+ ##
56
+ # Print the graph to stdout, based on the print mode & scale
57
+ #
58
+ def print(mode = nil)
59
+ case mode || @mode
60
+ when PrintMode::NOSCALE
61
+ print_noscale
62
+ when PrintMode::SCALE
63
+ print_scale
64
+ else
65
+ raise ArgumentError, 'Invalid Print Mode', caller
66
+ end
67
+ end
68
+
69
+ ##
70
+ # Print the graph without any scaling
71
+ #
72
+ def print_noscale
73
+ print_scale 1
74
+ end
75
+
76
+ ##
77
+ # Prints graph with a scale. Scale of 10 means every 10 values
78
+ # is displayed as 1 character
26
79
  #
27
- def print
80
+ def print_scale(scale = nil)
81
+ scale ||= @scale
28
82
  @data.each_with_index do |count, index|
29
- printf "%02d|%s\n", index, ('#' * count)
83
+ printf "%02d|%s\n", index, ('#' * (count / scale))
30
84
  end
31
85
  end
32
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graph-bar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caleb Smith