keycounter 0.0.2 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/keycounter.rb +23 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b74d39ab044f817903f9037596d7f3874cba9045
|
4
|
+
data.tar.gz: 3c0aaae49c4899882893d5bb59d56bcf57b53e2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e907e4ce2b836a9f22b589d5c0ff99b55487375c0479e8e6cd0375fa34a5bd5af0fc95540cb5a3759e61ec5e97914ec954ca76d7ed75f09263e875502e9b1136
|
7
|
+
data.tar.gz: 7e1c89a294b717cfaf96dc9c736e9b5b7035022328246a1c60df669ac97b992e851fea561cffa26b224705ed560fa370580f9780faa98ecd22019fd9991ffc8e
|
data/lib/keycounter.rb
CHANGED
@@ -10,15 +10,33 @@
|
|
10
10
|
|
11
11
|
class Keycounter
|
12
12
|
|
13
|
+
attr_writer :verbose
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@verbose = true
|
17
|
+
end
|
18
|
+
|
13
19
|
# Create / Add to instance variable
|
14
20
|
def keycount(key)
|
15
21
|
key.gsub!(" ", "_") # no spaces or case
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
begin
|
23
|
+
if !instance_variable_get("@#{key}")
|
24
|
+
instance_variable_set("@#{key}", 1)
|
25
|
+
else
|
26
|
+
begin
|
27
|
+
instance_variable_set("@#{key}", instance_variable_get("@#{key}") + 1)
|
28
|
+
rescue => e
|
29
|
+
puts "Cannot set instance variable of this name..."
|
30
|
+
pp e
|
31
|
+
end
|
32
|
+
end
|
33
|
+
rescue
|
34
|
+
puts "Cannot get instance variable of this name..."
|
35
|
+
pp e
|
36
|
+
end
|
37
|
+
if @verbose == true
|
38
|
+
puts "Key: #{key} Value: "+instance_variable_get("@#{key}").to_s
|
20
39
|
end
|
21
|
-
puts "Key: #{key} Value: "+instance_variable_get("@#{key}").to_s
|
22
40
|
end
|
23
41
|
|
24
42
|
# Read a single key
|