hexit 1.0.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 +7 -0
- data/lib/hexit.rb +67 -0
- metadata +45 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 25585081639bf3fea2aea4e35b8fe1fb4e9327ef
|
|
4
|
+
data.tar.gz: bcf7338bd5ae8a93eb49c26ba012f9251cf48a6a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: dbe0fe18bca4bc19cd60d83a63b8c29239e1dd73e5c02d7ac9f6a5e018f050e852497f9ec4d4e1e8ba3618fb644dd67c81f2d44e935957d39219c384198fc064
|
|
7
|
+
data.tar.gz: cc65c81dfb5f0629b95047bbd9254a46ca619e3b94a5e60e66f36273308d58562a6541a271b65818e860f62873e42806b62f02975d556106a778b6f3dd9350ad
|
data/lib/hexit.rb
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
class Hexit
|
|
2
|
+
attr_accessor :text, :colors
|
|
3
|
+
|
|
4
|
+
def initialize(text='', colors=[])
|
|
5
|
+
@text = text
|
|
6
|
+
@colors= colors
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def text_to_colors
|
|
10
|
+
colors = []
|
|
11
|
+
hex = []
|
|
12
|
+
|
|
13
|
+
text = @text.strip.delete(' ')
|
|
14
|
+
text.chars do |c|
|
|
15
|
+
hex << c.unpack('H2')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
hex = hex.join('')
|
|
19
|
+
hex.scan(/.{6}/).each do |color|
|
|
20
|
+
colors << '#' + color
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
colors
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def words_to_colors
|
|
27
|
+
colors = []
|
|
28
|
+
text_array = @text.split(' ')
|
|
29
|
+
text_array.each do |word|
|
|
30
|
+
hex = ''
|
|
31
|
+
word_bytes = word.bytes
|
|
32
|
+
word_bytes.each do |bytes|
|
|
33
|
+
hex += bytes.to_s
|
|
34
|
+
end
|
|
35
|
+
while hex.length < 6
|
|
36
|
+
hex += "F"
|
|
37
|
+
end
|
|
38
|
+
colors << "#" + hex.slice(0..5)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
colors
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def colors_to_text
|
|
45
|
+
hex = @colors.each do |color|
|
|
46
|
+
color.strip.sub('#', '')
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
text = []
|
|
50
|
+
|
|
51
|
+
hex.each do |h|
|
|
52
|
+
text << h.to_s.gsub('#', '')
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
output = ''
|
|
56
|
+
|
|
57
|
+
text_for_pack = text.join('').scan(/.{2}/)
|
|
58
|
+
|
|
59
|
+
text_for_pack.each do |t|
|
|
60
|
+
h = []
|
|
61
|
+
h << t
|
|
62
|
+
output << h.pack('H*')
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
output.force_encoding('UTF-8')
|
|
66
|
+
end
|
|
67
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: hexit
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Andrew Bales
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-03-23 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Provides methods to translate text into color array or color array into
|
|
14
|
+
text. Further allows for conversion of words into individual colors.
|
|
15
|
+
email: agbales@gmail.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/hexit.rb
|
|
21
|
+
homepage: http://rubygems.org/gems/hexit
|
|
22
|
+
licenses:
|
|
23
|
+
- MIT
|
|
24
|
+
metadata: {}
|
|
25
|
+
post_install_message:
|
|
26
|
+
rdoc_options: []
|
|
27
|
+
require_paths:
|
|
28
|
+
- lib
|
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
requirements: []
|
|
40
|
+
rubyforge_project:
|
|
41
|
+
rubygems_version: 2.6.10
|
|
42
|
+
signing_key:
|
|
43
|
+
specification_version: 4
|
|
44
|
+
summary: Converts text to hex colors or vice versa
|
|
45
|
+
test_files: []
|