samantha 0.0.4 → 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/bin/samantha +1 -1
- data/lib/samantha/version.rb +1 -1
- data/lib/samantha.rb +35 -27
- 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: a65b336028562cc70baeee5a52a897a27d2f37be
|
4
|
+
data.tar.gz: 64a85243c31799824b2a9758ae4a120759d45246
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 481f635439fd2b4d4c54748be6a4d4c63205c133e29d9095171a1aa02ab82dd0dcd7e718c9f4c49ed9c074dadeb100bca729222994e413b73fde822d7caf1c34
|
7
|
+
data.tar.gz: a9d60942595c2b428eefc1e9606a82547c3f0cb3139dac6a4101e861fe39624dd3846ed91ac8d6703d1f7b059e677ac991e120a89e988943a650e55ad4ba47c1
|
data/bin/samantha
CHANGED
data/lib/samantha/version.rb
CHANGED
data/lib/samantha.rb
CHANGED
@@ -10,48 +10,56 @@ module Samantha
|
|
10
10
|
@colors = []
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
Dir["#{
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
13
|
+
def find_colors_in_directory(directory)
|
14
|
+
Dir["#{directory}/*"].each do |file| find_colors_in_file(file) end
|
15
|
+
end
|
16
|
+
|
17
|
+
def find_colors_in_file(file)
|
18
|
+
File.open(file) do |file_contents|
|
19
|
+
file_contents.each_line do |line|
|
20
|
+
find_colors_in_line(line)
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
|
-
def
|
27
|
-
|
28
|
-
if a == nil
|
29
|
-
@colors.push(color)
|
30
|
-
else
|
31
|
-
a.count += 1
|
32
|
-
end
|
25
|
+
def find_colors_in_line(line)
|
26
|
+
line.scan(/\B#[0-9a-fA-f]{3,6}\b/).each do |hex| add_colors_from_line(hex) end
|
33
27
|
end
|
34
28
|
|
35
|
-
def
|
36
|
-
|
29
|
+
def add_colors_from_line(hex)
|
30
|
+
add_color(Color.new(hex.downcase))
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_color(color)
|
34
|
+
existing_color = @colors.detect { |c| c.hex == color.hex }
|
35
|
+
existing_color ? existing_color.tally : @colors.push(color)
|
36
|
+
end
|
37
37
|
|
38
|
-
|
39
|
-
@colors.reverse!
|
38
|
+
def sort_colors
|
39
|
+
@colors.sort_by! { |c| c.count }.reverse!
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
puts
|
42
|
+
def print(directory)
|
43
|
+
find_colors_in_directory(directory)
|
44
|
+
sort_colors()
|
45
|
+
@colors.each do |color| puts color end
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
class Color
|
50
50
|
attr_accessor :hex, :count
|
51
51
|
|
52
|
-
def initialize(hex
|
52
|
+
def initialize(hex)
|
53
53
|
@hex = hex
|
54
|
-
@count =
|
54
|
+
@count = 1
|
55
|
+
end
|
56
|
+
|
57
|
+
def tally
|
58
|
+
@count += 1
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_s
|
62
|
+
"#{Paint['●', @hex, nil]} ##{@hex.ljust(6)} #{@count.to_s}"
|
55
63
|
end
|
56
64
|
end
|
57
65
|
|