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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6392430cb7ccc85c8ae39a4078df65cb688a720f
4
- data.tar.gz: 9d48e0aef594e8ebfacbf8389c5bdf1fc9033515
3
+ metadata.gz: a65b336028562cc70baeee5a52a897a27d2f37be
4
+ data.tar.gz: 64a85243c31799824b2a9758ae4a120759d45246
5
5
  SHA512:
6
- metadata.gz: c32a4972cc24fa6149afb46072d177daf389507fb411a44015f7a5642829ebc8fc51d5746007f0e8068b8613a38276bdcdda65b0a1591b40272318db53c16ab3
7
- data.tar.gz: f2b8f7e32285fef5ead1e0c9c5863443e5956687b13408a88698cea2db7343d6cb1070b371dbe8cab64e68b138d4db1469956954f998104351e06a6b5e1bd608
6
+ metadata.gz: 481f635439fd2b4d4c54748be6a4d4c63205c133e29d9095171a1aa02ab82dd0dcd7e718c9f4c49ed9c074dadeb100bca729222994e413b73fde822d7caf1c34
7
+ data.tar.gz: a9d60942595c2b428eefc1e9606a82547c3f0cb3139dac6a4101e861fe39624dd3846ed91ac8d6703d1f7b059e677ac991e120a89e988943a650e55ad4ba47c1
data/bin/samantha CHANGED
@@ -4,4 +4,4 @@ require 'samantha'
4
4
 
5
5
  samantha = Samantha::Palette.new
6
6
 
7
- samantha.print_colors(*ARGV)
7
+ samantha.print(*ARGV)
@@ -1,3 +1,3 @@
1
1
  module Samantha
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/samantha.rb CHANGED
@@ -10,48 +10,56 @@ module Samantha
10
10
  @colors = []
11
11
  end
12
12
 
13
- def find_colors(dir)
14
- Dir["#{dir}/*"].each do |f|
15
- File.open(f) do |f|
16
- f.each_line do |l|
17
- l.scan(/\B#[0-9a-fA-f]{3,6}\b/).each do |hex|
18
- hex = hex.downcase
19
- add_color(Color.new(hex, 1))
20
- end
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 add_color(color)
27
- a = @colors.detect { |c| c.hex == color.hex }
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 print_colors(dir)
36
- find_colors(dir)
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
- @colors.sort_by! { |c| c.count }
39
- @colors.reverse!
38
+ def sort_colors
39
+ @colors.sort_by! { |c| c.count }.reverse!
40
+ end
40
41
 
41
- puts Paint['', nil, nil]
42
- @colors.each do |c|
43
- puts "#{Paint['●', c.hex, nil]} ##{c.hex.ljust(6)} #{c.count.to_s.ljust(6)}"
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, count)
52
+ def initialize(hex)
53
53
  @hex = hex
54
- @count = 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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: samantha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flip Stewart