hashtel 0.0.1 → 0.0.2

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: 6d8b8ebcd3389ab89c4ebefb9468a4517ab97373
4
- data.tar.gz: d8561016bad740db6853d999d04fd2cf8440ff56
3
+ metadata.gz: 6c8600d8376114c28b41dbf60d1fa7858d9273e8
4
+ data.tar.gz: 1a263306d723e66c1d4c5f28271bb67c16b4d060
5
5
  SHA512:
6
- metadata.gz: 8278621043d3e5d7841a7d62a4df6142754eed86138aa75ce1181d66609de3c2da0d10d546299f8da5bfb386ff13aa66d08eace86841f94321cd3f6a2f506818
7
- data.tar.gz: d4ba192ad95b6ee023c799a6c33c8206456a77f2772b9043f595e9931e76faacfac57ecf3b69dd066939db6e1000e78b5d2395b3effc0e1f0f9717d3e33cc06c
6
+ metadata.gz: 4cd4004410090742f0e9e11167c142ee8ad6f64f8095822680f2aa3587ff56ccca3cfede9f8a8887b6fce75b9bb70197d879d7ce011839424865b6ae03812896
7
+ data.tar.gz: cae93e570a620a4c9494814747fa81d189feaa8538eb41fbb4b6521faef77c21d500a592cf536815f7ba5d872402139c9a334ee7d54e0f4dd6fc0696fe40376a
@@ -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 hashtel.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 jurre
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.
@@ -0,0 +1,56 @@
1
+ # Hashtel
2
+
3
+ Get a consistent (pretty) hex color from your strings.
4
+
5
+ This allows you to show nice colors in your UI's that
6
+ are consistent throughout your application.
7
+
8
+ Some ideas to use this for: users without avatars,
9
+ charts, categories etc.
10
+
11
+ Objective-C and Javascript versions are coming soon.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'hashtel'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install hashtel
26
+
27
+ ## Usage
28
+
29
+ ```ruby
30
+ "wow".pastel_color
31
+ # => "#606BE5"
32
+
33
+ "very color".pastel_color
34
+ # => "#789D9B"
35
+
36
+ "such pretty".pastel_color
37
+ # => "#87BD6C"
38
+
39
+ "wow".pastel_color
40
+ # => "#606BE5"
41
+ ```
42
+
43
+ ![wow](https://raw.github.com/jurre/hashtel/master/img/wow.png)
44
+ ![very color](https://raw.github.com/jurre/hashtel/master/img/very-color.png)
45
+ ![such pretty](https://raw.github.com/jurre/hashtel/master/img/such-pretty.png)
46
+
47
+ Example usage:
48
+ ![Hours](https://raw.github.com/jurre/hashtel/master/img/example.png)
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it ( http://github.com/jurre/hashtel/fork )
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hashtel/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hashtel"
8
+ spec.version = Hashtel::VERSION
9
+ spec.authors = ["Jurre Stender"]
10
+ spec.email = ["jurrestender+github@gmail.com"]
11
+ spec.summary = %q{Consistently convert strings to the same (pretty) color}
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files`.split("\n")
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_development_dependency "bundler", "~> 1.5"
19
+ spec.add_development_dependency "rspec"
20
+ spec.add_development_dependency "rake"
21
+ end
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,39 @@
1
+ require "hashtel/version"
2
+ require "hashtel/core_ext/string"
3
+
4
+ module Hashtel
5
+ def self.pastel_color(string)
6
+ return "#FFFFFF" if string == ""
7
+
8
+ hex_value = hashtel_hex_value(string)
9
+
10
+ "##{hex_value}".upcase
11
+ end
12
+
13
+
14
+ # Private methods
15
+
16
+ def self.hashtel_hex_value(string)
17
+ # magic numbers that create pretty colors
18
+ # whatevs, sue me (please don't sue me)
19
+ start_color = 92
20
+ total_offset = 156
21
+
22
+ [0,
23
+ hashtel_hash_code(string) % total_offset,
24
+ hashtel_hash_code(string.reverse) & total_offset,
25
+ total_offset].sort.each_cons(2).map do |a, b|
26
+ "%02x" % (start_color + b - a)
27
+ end.join
28
+ end
29
+ private_class_method :hashtel_hex_value
30
+
31
+ def self.hashtel_hash_code(string)
32
+ return string.ord << 3 if string.length == 1
33
+ string.split("").reduce do |memo, obj|
34
+ hash = ((memo.ord << 3) - memo.ord) + obj.ord
35
+ (hash & hash).abs
36
+ end
37
+ end
38
+ private_class_method :hashtel_hash_code
39
+ end
@@ -0,0 +1,7 @@
1
+ require_relative "../../hashtel"
2
+
3
+ class String
4
+ def pastel_color
5
+ Hashtel.pastel_color(self)
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Hashtel
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,24 @@
1
+ require "hashtel"
2
+
3
+ HEX_COLOR_MAX_INTEGER = 16777215
4
+
5
+ describe String do
6
+ describe "#pastel_color" do
7
+ it "returns a valid hex color" do
8
+ random_string = (0...rand(50)).map { ("a".."z").to_a[rand(26)] }.join
9
+ expect(hex_value(random_string)).to be_between(0, HEX_COLOR_MAX_INTEGER)
10
+ end
11
+
12
+ it "returns white for empty strings" do
13
+ expect("".pastel_color).to eq("#FFFFFF")
14
+ end
15
+
16
+ it "works on single character strings" do
17
+ expect(hex_value("a".pastel_color)).to be_between(0, HEX_COLOR_MAX_INTEGER)
18
+ end
19
+ end
20
+
21
+ def hex_value(string)
22
+ string[1..-1].hex
23
+ end
24
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashtel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurre Stender
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-01 00:00:00.000000000 Z
11
+ date: 2014-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,7 +58,21 @@ email:
58
58
  executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
- files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - hashtel.gemspec
68
+ - img/example.png
69
+ - img/such-pretty.png
70
+ - img/very-color.png
71
+ - img/wow.png
72
+ - lib/hashtel.rb
73
+ - lib/hashtel/core_ext/string.rb
74
+ - lib/hashtel/version.rb
75
+ - spec/lib/hashtel_spec.rb
62
76
  homepage:
63
77
  licenses:
64
78
  - MIT
@@ -83,4 +97,5 @@ rubygems_version: 2.2.0
83
97
  signing_key:
84
98
  specification_version: 4
85
99
  summary: Consistently convert strings to the same (pretty) color
86
- test_files: []
100
+ test_files:
101
+ - spec/lib/hashtel_spec.rb