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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a65b336028562cc70baeee5a52a897a27d2f37be
4
- data.tar.gz: 64a85243c31799824b2a9758ae4a120759d45246
3
+ metadata.gz: 06ec55fd31ee86f1543cb2728771057cf428018a
4
+ data.tar.gz: 86c29217d23778a4d644f4a87b4942bdb8fd1ab2
5
5
  SHA512:
6
- metadata.gz: 481f635439fd2b4d4c54748be6a4d4c63205c133e29d9095171a1aa02ab82dd0dcd7e718c9f4c49ed9c074dadeb100bca729222994e413b73fde822d7caf1c34
7
- data.tar.gz: a9d60942595c2b428eefc1e9606a82547c3f0cb3139dac6a4101e861fe39624dd3846ed91ac8d6703d1f7b059e677ac991e120a89e988943a650e55ad4ba47c1
6
+ metadata.gz: 6307473d66bfba03a75e9181bf16be0d01cf9dbd4edf366b09bf744f68f97da6a11f93d5b8ef2a0c5bfc1b1039c69e649b62f7dd1d8e596a54e48c702fa268ad
7
+ data.tar.gz: 3006b69aec5c91715ca6e8838cc2956d791e4f65fb07ac1e0fcd5dd293761a28834c054a8e1a475309554249dce5b0308eb766137c6b6fbce7f7cf38775cb281
data/Gemfile.lock ADDED
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ samantha (0.0.7)
5
+ paint (= 0.8.6)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ paint (0.8.6)
11
+ rake (10.1.0)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.3)
18
+ rake
19
+ samantha!
data/bin/samantha CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'samantha'
3
+ require "samantha"
4
4
 
5
- samantha = Samantha::Palette.new
5
+ samantha = Samantha::Base.new
6
6
 
7
- samantha.print(*ARGV)
7
+ samantha.print_colors_in_directory(*ARGV)
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
- module Samantha
5
-
6
- class Palette
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
- 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
-
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
- def tally
58
- @count += 1
10
+ class Base
11
+ def initialize
12
+ @hex_aggregator = Hex_Aggregator.new
13
+ @palette = Palette.new
59
14
  end
60
15
 
61
- def to_s
62
- "#{Paint['●', @hex, nil]} ##{@hex.ljust(6)} #{@count.to_s}"
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
@@ -1,3 +1,3 @@
1
1
  module Samantha
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.7"
3
3
  end
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.5
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-03 00:00:00.000000000 Z
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
- - .gitignore
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
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
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