tiedye 0.1.0

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NjYxMGJlMTgxZDU5NjZkOWNmMTBmY2QwODlkMzcyMjRmZGJkNDdhZQ==
5
+ data.tar.gz: !binary |-
6
+ MTQ3MjA4MjM0OWNmNzE4OTUzOTU0NDI0MGQ4ZGRhMmU3MTJmOTQ3Zg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OTEyYjZmMWY2NzIxYzllZmMxM2U3NTQzOTNlZWYwYzQ2ZDAyNmM1NmYzNTQ4
10
+ MTYzY2JlYjY5OTUxZGM5MTY2Njc0NTQ0MmU5NGI2MjRiNjNlOThhYzEyNDU3
11
+ OTg4OTg0ZTkwNDUzZTI1NGJmOGU0N2QxZTA4OGM5YjMwYTlmNjM=
12
+ data.tar.gz: !binary |-
13
+ MTc1M2NhZTFlOTE2ZjcyZDM1MDcxMTU5YzNiYTYzMTMwYzZjY2Y2ZjM1MGVl
14
+ NTZmMzlkYzcyODBkZjQ4M2M3Mzk3MzI3MTIyZTVhYzI2MTU1ZjBiYTdkOTk4
15
+ ZDc5MWZlMmNiZTYyNzY1Y2E3OTc0MTE0NDM0YTVkNzc5MjgxNGE=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tiedye.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 John Maddux
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Tiedye
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'tiedye'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install tiedye
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'lib/tiedye'
8
+ t.test_files = FileList['test/lib/tiedye/*_test.rb']
9
+ t.verbose = true
10
+ end
11
+
12
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ module Tiedye
2
+ VERSION = "0.1.0"
3
+ end
data/lib/tiedye.rb ADDED
@@ -0,0 +1,86 @@
1
+ require "tiedye/version"
2
+
3
+ module Tiedye
4
+ def self.to_rgb(hex)
5
+ hex = to_6_hex(hex)
6
+ hex_pairs = hex.scan(/.{1,2}/)
7
+ rgb = []
8
+ rgb[0] = hex_pair_to_rgb_digit(hex_pairs[0])
9
+ rgb[1] = hex_pair_to_rgb_digit(hex_pairs[1])
10
+ rgb[2] = hex_pair_to_rgb_digit(hex_pairs[2])
11
+ return rgb
12
+ end
13
+
14
+ def self.to_hex(r = "x", g = "x", b = "x")
15
+ return random_hex if invalid(r, g, b)
16
+ r, g, b = rgb_float_to_int(r, g, b)
17
+ return "#" + hex_digit(r) + hex_digit(g) + hex_digit(b)
18
+ end
19
+
20
+ def self.method_missing(name, *args)
21
+ return COLORS[name.to_s.downcase] if COLORS[name.to_s.downcase]
22
+ return name
23
+ end
24
+
25
+ private
26
+ def self.hex_pair_to_rgb_digit(hex_pair)
27
+ hexz = hex_pair.split("")
28
+ number = HEX_DIGIT.key(hexz[0]) * 16
29
+ number += HEX_DIGIT.key(hexz[1])
30
+ return number
31
+ end
32
+
33
+ def self.to_6_hex(hex)
34
+ hex = hex.gsub("#", "")
35
+ if hex.length == 3
36
+ letters = hex.split("")
37
+ hex = ""
38
+ letters.each do |letter|
39
+ hex += letter + letter
40
+ end
41
+ end
42
+ return hex
43
+ end
44
+
45
+ def self.random_hex
46
+ hex = "#"
47
+ 3.times do
48
+ hex += hex_digit(rand(0..255))
49
+ end
50
+ return hex
51
+ end
52
+
53
+ def self.hex_digit(digit)
54
+ return HEX_DIGIT[digit / 16] + HEX_DIGIT[digit % 16]
55
+ end
56
+
57
+ def self.rgb_float_to_int(r, g, b)
58
+ if r.class == Float && r <= 1 && g <= 1 && b <= 1
59
+ r = (r * 255).to_i
60
+ g = (g * 255).to_i
61
+ b = (b * 255).to_i
62
+ end
63
+ return [r, g, b]
64
+ end
65
+
66
+ def self.invalid(r, g, b)
67
+ begin
68
+ [r, g, b].each do |x|
69
+ return true if x == "x"
70
+ return true if x > 255 || x < 0
71
+ end
72
+ rescue
73
+ return false
74
+ end
75
+ return false
76
+ end
77
+
78
+ HEX_DIGIT = {
79
+ 0 => "0", 1 => "1", 2 => "2", 3 => "3", 4 => "4",
80
+ 5 => "5", 6 => "6", 7 => "7", 8 => "8", 9 => "9",
81
+ 10 => "A", 11 => "B", 12 => "C", 13 => "D", 14 => "E", 15 => "F",
82
+ }
83
+
84
+ COLORS = {"blue" => "#003DFF", "red" => "#FF0014"}
85
+ end
86
+
@@ -0,0 +1,7 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Tiedye do
4
+ it "must be defined" do
5
+ Tiedye::VERSION.wont_be_nil
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ $:.unshift('.')
2
+
3
+ require 'minitest/autorun'
4
+ require 'minitest/pride'
5
+ require File.expand_path("../../lib/tiedye.rb", __FILE__)
data/tiedye.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tiedye/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tiedye"
8
+ spec.version = Tiedye::VERSION
9
+ spec.authors = ["John Maddux"]
10
+ spec.email = ["jemaddux@gmail.com"]
11
+ spec.description = %q{Change colors from hex to rgb or named value}
12
+ spec.summary = %q{Colors!}
13
+ spec.homepage = "https://github.com/jemaddux/tiedye"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
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
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tiedye
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - John Maddux
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Change colors from hex to rgb or named value
42
+ email:
43
+ - jemaddux@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/tiedye.rb
54
+ - lib/tiedye/version.rb
55
+ - test/lib/tiedye/version_test.rb
56
+ - test/test_helper.rb
57
+ - tiedye.gemspec
58
+ homepage: https://github.com/jemaddux/tiedye
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.2.1
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Colors!
82
+ test_files:
83
+ - test/lib/tiedye/version_test.rb
84
+ - test/test_helper.rb
85
+ has_rdoc: