samantha 0.0.5 → 0.0.7
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 +4 -4
- data/Gemfile.lock +19 -0
- data/bin/samantha +3 -3
- data/lib/colors.rb +20 -0
- data/lib/hex_aggregator.rb +25 -0
- data/lib/palette.rb +20 -0
- data/lib/samantha.rb +14 -57
- data/lib/samantha/version.rb +1 -1
- metadata +9 -7
- data/.gitignore +0 -17
- data/samantha.gemspec +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06ec55fd31ee86f1543cb2728771057cf428018a
|
4
|
+
data.tar.gz: 86c29217d23778a4d644f4a87b4942bdb8fd1ab2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6307473d66bfba03a75e9181bf16be0d01cf9dbd4edf366b09bf744f68f97da6a11f93d5b8ef2a0c5bfc1b1039c69e649b62f7dd1d8e596a54e48c702fa268ad
|
7
|
+
data.tar.gz: 3006b69aec5c91715ca6e8838cc2956d791e4f65fb07ac1e0fcd5dd293761a28834c054a8e1a475309554249dce5b0308eb766137c6b6fbce7f7cf38775cb281
|
data/Gemfile.lock
ADDED
data/bin/samantha
CHANGED
data/lib/colors.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Samantha
|
2
|
+
|
3
|
+
class Color
|
4
|
+
attr_accessor :hex, :count
|
5
|
+
|
6
|
+
def initialize(hex)
|
7
|
+
@hex = hex
|
8
|
+
@count = 1
|
9
|
+
end
|
10
|
+
|
11
|
+
def tally
|
12
|
+
@count += 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
"#{Paint['●', @hex, nil]} ##{@hex.ljust(6)} #{@count.to_s}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Samantha
|
2
|
+
|
3
|
+
class Hex_Aggregator
|
4
|
+
attr_accessor :hexes
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@hexes = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def find_colors_in_directory(directory)
|
11
|
+
Dir["#{directory}/*"].map { |file| find_colors_in_file(file) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def find_colors_in_file(file)
|
15
|
+
File.open(file) do |file_contents|
|
16
|
+
file_contents.each_line { |line| find_colors_in_line(line) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_colors_in_line(line)
|
21
|
+
line.scan(/\B#[0-9a-fA-f]{3,6}\b/).each {|hex| @hexes.push(hex)}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/lib/palette.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Samantha
|
2
|
+
|
3
|
+
class Palette
|
4
|
+
attr_accessor :colors
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@colors = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_color(hex)
|
11
|
+
existing_color = @colors.detect { |c| c.hex == hex }
|
12
|
+
existing_color ? existing_color.tally : @colors.push(Color.new(hex.downcase))
|
13
|
+
end
|
14
|
+
|
15
|
+
def sort_colors
|
16
|
+
@colors.sort_by! { |c| c.count }.reverse!
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/samantha.rb
CHANGED
@@ -1,67 +1,24 @@
|
|
1
1
|
require "samantha/version"
|
2
2
|
require "paint"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
attr_accessor :colors
|
8
|
-
|
9
|
-
def initialize()
|
10
|
-
@colors = []
|
11
|
-
end
|
12
|
-
|
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)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
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
|
27
|
-
end
|
28
|
-
|
29
|
-
def add_colors_from_line(hex)
|
30
|
-
add_color(Color.new(hex.downcase))
|
31
|
-
end
|
4
|
+
require_relative "colors"
|
5
|
+
require_relative "hex_aggregator"
|
6
|
+
require_relative "palette"
|
32
7
|
|
33
|
-
|
34
|
-
existing_color = @colors.detect { |c| c.hex == color.hex }
|
35
|
-
existing_color ? existing_color.tally : @colors.push(color)
|
36
|
-
end
|
37
|
-
|
38
|
-
def sort_colors
|
39
|
-
@colors.sort_by! { |c| c.count }.reverse!
|
40
|
-
end
|
41
|
-
|
42
|
-
def print(directory)
|
43
|
-
find_colors_in_directory(directory)
|
44
|
-
sort_colors()
|
45
|
-
@colors.each do |color| puts color end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class Color
|
50
|
-
attr_accessor :hex, :count
|
51
|
-
|
52
|
-
def initialize(hex)
|
53
|
-
@hex = hex
|
54
|
-
@count = 1
|
55
|
-
end
|
8
|
+
module Samantha
|
56
9
|
|
57
|
-
|
58
|
-
|
10
|
+
class Base
|
11
|
+
def initialize
|
12
|
+
@hex_aggregator = Hex_Aggregator.new
|
13
|
+
@palette = Palette.new
|
59
14
|
end
|
60
15
|
|
61
|
-
def
|
62
|
-
|
16
|
+
def print_colors_in_directory(directory)
|
17
|
+
@hex_aggregator.find_colors_in_directory(directory)
|
18
|
+
@hex_aggregator.hexes.each { |hex| @palette.add_color(hex) }
|
19
|
+
@palette.sort_colors
|
20
|
+
@palette.colors.each { |color| puts color }
|
63
21
|
end
|
64
22
|
end
|
65
23
|
|
66
|
-
end
|
67
|
-
|
24
|
+
end
|
data/lib/samantha/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: samantha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Flip Stewart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,15 +60,17 @@ executables:
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
-
- .
|
63
|
+
- lib/colors.rb
|
64
|
+
- lib/hex_aggregator.rb
|
65
|
+
- lib/palette.rb
|
66
|
+
- lib/samantha.rb
|
67
|
+
- lib/samantha/version.rb
|
68
|
+
- bin/samantha
|
64
69
|
- Gemfile
|
70
|
+
- Gemfile.lock
|
65
71
|
- LICENSE.txt
|
66
72
|
- README.md
|
67
73
|
- Rakefile
|
68
|
-
- bin/samantha
|
69
|
-
- lib/samantha.rb
|
70
|
-
- lib/samantha/version.rb
|
71
|
-
- samantha.gemspec
|
72
74
|
homepage: ''
|
73
75
|
licenses:
|
74
76
|
- MIT
|
data/.gitignore
DELETED
data/samantha.gemspec
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'samantha/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "samantha"
|
8
|
-
spec.version = Samantha::VERSION
|
9
|
-
spec.authors = ["Flip Stewart"]
|
10
|
-
spec.email = ["flipstewart@me.com"]
|
11
|
-
spec.description = %q{Hex code counter}
|
12
|
-
spec.summary = %q{Samantha finds all the hex color codes in a directory and displays them along with the number of times they occur}
|
13
|
-
spec.homepage = ""
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files`.split($/)
|
17
|
-
spec.executables = ["samantha"]
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
-
spec.add_development_dependency "rake"
|
23
|
-
|
24
|
-
spec.add_runtime_dependency('paint', '0.8.6')
|
25
|
-
end
|