servicon 0.0.2 → 0.0.3

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: 67eb6c2cdee267d29874d29e0c1af4f3d819bd8e
4
- data.tar.gz: 115c289f95f9883d9e4a159c7791c77abd84ad7f
3
+ metadata.gz: 7aa1d1becdc1cc492eb928a3055b3d1d068619f0
4
+ data.tar.gz: a4830cae2338ed88d8281031dfac712501412ebc
5
5
  SHA512:
6
- metadata.gz: cf60ad132646b99585e3a0cb4257cceb541314e5cd25af2e46ae2e65698c0228dc11f22cf96142896d781489e5e085895bd69c4145fe2ab40f4c35b8b595251f
7
- data.tar.gz: e011d13d312ae4d0b110177bc708388535f4ed02240347094b001043807d857ba23b9b0446c57e4febd4567ef3d3bb70570751568875e7cd2ecb4d8850c6d97a
6
+ metadata.gz: 11a6f44e56fbedc2c0313d9d0645b38d48b7094f916ed2752dc91701969f34cec82ee526f325c913bc1c5a96ac115a970c527dfc5ff6c1835132b2bfc420e8ce
7
+ data.tar.gz: 5f39ef628d0af3a13c1c347e4b95e942c8a771fda55963c2af1f771f2aedcf99e12b32604743d3d8d490bfae76ca48a068f39833523b7c621155e2910263470a
data/bin/servicon CHANGED
@@ -1,7 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
-
5
2
  require 'servicon'
3
+ Servicon::CLI.start
6
4
 
7
- exit Servicon::Bin.new(ARGV).run
@@ -0,0 +1,12 @@
1
+ Feature: Icon
2
+ In order to display or pluralize icon
3
+ As a CLI
4
+ I want to be as objective as possible
5
+
6
+ Scenario: Broccoli is gross
7
+ When I run `servicon uuid webserver`
8
+ Then the output should contain "4355734430"
9
+
10
+ Scenario: Tomato, or Tomato?
11
+ When I run `servicon pluralize --word Tomato`
12
+ Then the output should contain "Tomatoes"
@@ -0,0 +1 @@
1
+ require 'aruba/cucumber'
data/lib/servicon.rb CHANGED
@@ -1,79 +1,92 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require "servicon/version"
2
- require "servicon/bin"
3
+ require "servicon/cli"
3
4
  require "paint"
4
5
  require "digest"
5
6
 
6
7
  module Servicon
7
8
 
8
- class Servicon
9
- attr_accessor :key, :fingerprint, :identifier
9
+ class Icon
10
+ attr_accessor :fingerprint
10
11
 
11
- def initialize(fingerprint)
12
+ def initialize(fingerprint, color = options[:color])
13
+ color=="true" ? @color = true : @color = false
12
14
  @fingerprint = fingerprint
13
- @identifier = self.identifier
15
+ @uuid = self.uuid
14
16
  end
15
17
 
16
- def identifier
17
- identifier = Digest::MD5.hexdigest(@fingerprint).unpack('H*')[0].to_i(16)
18
+ def uuid
19
+ uuid = Digest::SHA1.hexdigest(@fingerprint).unpack('H*')[0].to_i(16)
20
+ return uuid
18
21
  end
19
22
 
20
23
  def matrix
21
24
  line = Array.new
22
25
  identicon = Array.new
23
26
 
24
- 63.downto(0) do |i|
25
- line << @identifier[i]
26
- if (i % 8 == 0)
27
- line << @identifier[i]
27
+ 0.upto(63) do |i|
28
+ line << @uuid[i]
29
+ if line.count == 8
28
30
  identicon << line + line.reverse
29
31
  line = Array.new
30
32
  end
31
33
  end
34
+
32
35
  return identicon
33
36
  end
34
37
 
35
38
  def rgb
36
39
  color = Hash.new
37
- color[:red] = (@identifier & 0xff)
38
- color[:blue] = ((@identifier >> 8) & 0xff)
39
- color[:green] = ((@identifier >> 16) & 0xff)
40
+ color[:red] = ((@uuid >> 4) & 0xff)
41
+ color[:blue] = ((@uuid >> 8) & 0xff)
42
+ color[:green] = ((@uuid >> 16) & 0xff)
43
+
40
44
  return color
41
45
  end
42
-
43
- def color(matrix_line)
44
- rgb = self.rgb
45
46
 
46
- red = rgb[:red]
47
- green = rgb[:green]
48
- blue = rgb[:blue]
47
+ def display
48
+ draw_matrix(matrix)
49
+ end
49
50
 
50
- line = Array.new
51
- matrix_line.each do |character|
52
- if character == 0
53
- line << Paint[' ', nil, [red, green, blue]]
54
- elsif character == 1
55
- line << Paint[' ', nil, [red / 2, green / 2, blue / 2]]
56
- end
51
+ def draw_matrix(matrix)
52
+ my_row = Array.new
53
+
54
+ matrix.each do |row|
55
+ my_row << draw_row(row)
57
56
  end
58
- return line.join
57
+
58
+ return my_row.join
59
59
  end
60
60
 
61
+ def draw_row(matrix_row)
62
+ line = Array.new
61
63
 
62
- def create
63
- matrix = self.matrix
64
-
65
- icon = String.new
66
- matrix.each do |line|
67
- icon = icon + color(line) + "\n"
64
+ matrix_row.each do |character|
65
+ line << draw_char(character)
68
66
  end
69
- return icon
67
+
68
+ return line.join + "\n"
70
69
  end
71
-
72
70
 
73
- class Servicon::NoCodeError < StandardError; end
71
+ def draw_char(character)
72
+ rgb = [self.rgb[:red], self.rgb[:green], self.rgb[:blue]]
73
+ rgb.collect! { |n| n / 2 } if character == 1
74
74
 
75
- end
75
+ background = :default
76
+ foreground = :default
77
+
78
+ if @color
79
+ background = rgb
80
+ else
81
+ background = :inverse if character == 1
82
+ end
76
83
 
84
+ Paint[" ", foreground, background]
85
+
86
+ end
87
+
88
+ end
77
89
 
90
+ class Servicon::NoCodeError < StandardError; end
78
91
 
79
92
  end
@@ -0,0 +1,17 @@
1
+ require 'thor'
2
+ require 'servicon'
3
+
4
+ module Servicon
5
+ class CLI < Thor
6
+ desc "uuid FINGERPRINT", "Displays the UUID generated for the FINGERPRINT"
7
+ def uuid(fingerprint)
8
+ puts Servicon::Icon.new(fingerprint, false).uuid
9
+ end
10
+
11
+ desc "display FINGERPRINT", "Displays the icon generated for the FINGERPRINT"
12
+ method_option :color, :default => "true", :aliases => "-c"
13
+ def display(fingerprint)
14
+ puts Servicon::Icon.new(fingerprint, options[:color]).display
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Servicon
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/servicon.gemspec CHANGED
@@ -19,6 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "paint"
22
+ spec.add_dependency "thor"
23
+ spec.add_development_dependency "cucumber"
24
+ spec.add_development_dependency "aruba"
22
25
  spec.add_development_dependency "bundler", "~> 1.3"
23
26
  spec.add_development_dependency "rake"
24
27
  spec.add_development_dependency "rspec"
@@ -1,18 +1,32 @@
1
1
  require 'servicon'
2
2
 
3
+ # Goal:
4
+ #
5
+ # icon = Servicon::Icon.new("webserver", color = 1, ascii = 1)
6
+ #
7
+ # puts icon.uuid
8
+ # puts icon.matrix
9
+ # puts icon.display
10
+ # puts icon.html
11
+
12
+
3
13
  describe Servicon do
4
14
  before(:all) do
5
- @servicon = Servicon::Servicon.new("webserver")
15
+ @servicon = Servicon::Icon.new("webserver")
6
16
  end
7
17
 
8
- it "gives a unique id" do
9
- @servicon.identifier.should eql(
18
+ it "displays the unique id" do
19
+ @servicon.uuid.should eql(
10
20
  22704338318629462888122409979625206231270005454074289634515086541537965794865)
11
21
  end
22
+
23
+ it "displays the matrix" do
24
+ @servicon.matrix.count.should eql(8)
25
+ end
12
26
 
13
- it "create a string" do
14
- puts @servicon.create
15
- @servicon.create.class.should eql(String)
27
+ it "displays the servicon" do
28
+ @servicon.display.should eql(8)
16
29
  end
30
+
17
31
 
18
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servicon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Sexton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-18 00:00:00.000000000 Z
11
+ date: 2013-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paint
@@ -24,6 +24,48 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: cucumber
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aruba
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: bundler
29
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,8 +122,10 @@ files:
80
122
  - README.md
81
123
  - Rakefile
82
124
  - bin/servicon
125
+ - features/icon.feature
126
+ - features/support/setup.rb
83
127
  - lib/servicon.rb
84
- - lib/servicon/bin.rb
128
+ - lib/servicon/cli.rb
85
129
  - lib/servicon/version.rb
86
130
  - servicon.gemspec
87
131
  - spec/servicon_spec.rb
@@ -110,4 +154,6 @@ signing_key:
110
154
  specification_version: 4
111
155
  summary: Generate ANSI or ASCII identicons
112
156
  test_files:
157
+ - features/icon.feature
158
+ - features/support/setup.rb
113
159
  - spec/servicon_spec.rb
data/lib/servicon/bin.rb DELETED
@@ -1,55 +0,0 @@
1
- require 'optparse'
2
-
3
- class Servicon::Bin
4
-
5
- def initialize(args)
6
- @args = args
7
- end
8
-
9
- def run
10
- help = <<-EOHELP
11
- Servicon
12
-
13
- Basic Command Line Usage:
14
- servicon [OPTIONS] [FINGERPRINT]
15
-
16
- FINGERPRINT Unique ID to generate identicon
17
-
18
- Options:
19
- EOHELP
20
-
21
- opts = OptionParser.new do |opts|
22
- opts.banner = help
23
-
24
- opts.on("--version", "Display current version.") do
25
- puts "servicon " + Servicon::VERSION
26
- return 0
27
- end
28
- end
29
-
30
- begin
31
- opts.parse!(@args)
32
- rescue OptionParser::InvalidOption
33
- puts "servicon: #{$!.message}"
34
- puts "servicon: try 'servicon --help' for more information"
35
- return 1
36
- end
37
-
38
- if @args[0].nil?
39
- puts "servicon: no fingerprint specified"
40
- puts "servicon: try 'servicon --help' for more information"
41
- return 1
42
- end
43
-
44
- begin
45
- return_val = 0
46
- i = Servicon::Servicon.new(@args[0])
47
- puts i.create
48
- return return_val
49
- rescue Servicon::Servicon::NoCodeError
50
- puts "servicon: no file specified or specified file does not exist"
51
- puts "servicon: try 'servicon --help' for more information"
52
- return 1
53
- end
54
- end
55
- end