idecon 0.1.2 → 0.1.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 +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/lib/idecon/version.rb +1 -1
- data/lib/idecon.rb +21 -16
- metadata +2 -7
- data/.idea/.gitignore +0 -3
- data/.idea/idecon.iml +0 -20
- data/.idea/misc.xml +0 -7
- data/.idea/modules.xml +0 -8
- data/.idea/vcs.xml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c76cb538a8f25b0af5313d79eb8a37c8a501f26a539f8d05e12a80f54c957c5
|
4
|
+
data.tar.gz: 44e44d8ade326b33fc205fa3d097c63ba6473316379046b1163b7edd68522642
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab491d24ee164d4aa48b4fdec1305f532eb4cf98b26fb99ff5c2e1aa94082d37e22943ffaa433d1cc3775e45c3d968894559f80f2d1788b7abebc7884812b912
|
7
|
+
data.tar.gz: 5c9439a92e25badeea39899a405bdf62d065fc1914b2c239f40f5341d7d937c318a7c3cd4da76bc647ce68a9c983579a302952f6adfa127ed1ed902134aa690a
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/lib/idecon/version.rb
CHANGED
data/lib/idecon.rb
CHANGED
@@ -8,10 +8,15 @@ module Idecon
|
|
8
8
|
class Error < StandardError; end
|
9
9
|
|
10
10
|
class Identicon
|
11
|
-
|
11
|
+
SQUARE_SIZE = 250
|
12
|
+
PIXEL_SIZE = SQUARE_SIZE / 5
|
13
|
+
DEFAULT_PATH = 'default.png'
|
14
|
+
BACKGROUND_COLOR = [255, 255, 255].freeze
|
15
|
+
|
16
|
+
def initialize(user_name, path = DEFAULT_PATH)
|
12
17
|
@hash = Digest::MD5.hexdigest(user_name)
|
13
18
|
@path = path
|
14
|
-
@color =
|
19
|
+
@color = color
|
15
20
|
end
|
16
21
|
|
17
22
|
def generate
|
@@ -25,40 +30,40 @@ module Idecon
|
|
25
30
|
# Create matrix, where @colour - coloured square,
|
26
31
|
# [255, 255, 255] - empty square
|
27
32
|
def create_matrix
|
28
|
-
color
|
29
33
|
@matrix = @hash.chars[0..24].map do |c|
|
30
|
-
c
|
31
|
-
@color
|
32
|
-
else [255, 255, 255]
|
33
|
-
end
|
34
|
-
c
|
34
|
+
c.to_i(36).odd? ? @color : BACKGROUND_COLOR
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
# Get color from hash
|
39
39
|
def color
|
40
|
-
@
|
40
|
+
@hash[23..32].scan(/([\w\d])([\w\d])([\w\d])/).map do |arr|
|
41
41
|
color = 0
|
42
42
|
# Convert every character to a two-digit number, then get second digit
|
43
43
|
arr.each_with_index do |c, i|
|
44
|
-
color += 10**i *
|
44
|
+
color += 10**i * c.to_i(36)
|
45
45
|
end
|
46
|
-
color
|
46
|
+
color % 256
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
# Create image using ChunkyPNG by painting squares
|
51
51
|
def create_image
|
52
|
-
@image = ChunkyPNG::Image.new(
|
52
|
+
@image = ChunkyPNG::Image.new(SQUARE_SIZE, SQUARE_SIZE,
|
53
|
+
ChunkyPNG::Color.rgb(0, 0, 0))
|
53
54
|
@matrix.each_with_index do |color, i|
|
54
55
|
square = [i / 5, i % 5]
|
55
|
-
|
56
|
-
(square[0] + 1) * 50, (square[1] + 1) * 50,
|
57
|
-
ChunkyPNG::Color::TRANSPARENT,
|
58
|
-
ChunkyPNG::Color.rgb(color[0], color[1], color[2]))
|
56
|
+
draw_square(square, color)
|
59
57
|
end
|
60
58
|
end
|
61
59
|
|
60
|
+
def draw_square(square, color)
|
61
|
+
@image.rect(square[0] * PIXEL_SIZE, square[1] * PIXEL_SIZE,
|
62
|
+
(square[0] + 1) * PIXEL_SIZE, (square[1] + 1) * PIXEL_SIZE,
|
63
|
+
ChunkyPNG::Color::TRANSPARENT,
|
64
|
+
ChunkyPNG::Color.rgb(color[0], color[1], color[2]))
|
65
|
+
end
|
66
|
+
|
62
67
|
def save_image(path)
|
63
68
|
@image.save(path)
|
64
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: idecon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02
|
11
|
+
date: 2020-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chunky_png
|
@@ -74,11 +74,6 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
|
-
- ".idea/.gitignore"
|
78
|
-
- ".idea/idecon.iml"
|
79
|
-
- ".idea/misc.xml"
|
80
|
-
- ".idea/modules.xml"
|
81
|
-
- ".idea/vcs.xml"
|
82
77
|
- ".rspec"
|
83
78
|
- ".travis.yml"
|
84
79
|
- CHANGELOG.md
|
data/.idea/.gitignore
DELETED
data/.idea/idecon.iml
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<module type="RUBY_MODULE" version="4">
|
3
|
-
<component name="ModuleRunConfigurationManager">
|
4
|
-
<shared />
|
5
|
-
</component>
|
6
|
-
<component name="NewModuleRootManager">
|
7
|
-
<content url="file://$MODULE_DIR$" />
|
8
|
-
<orderEntry type="inheritedJdk" />
|
9
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
10
|
-
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.0.2, RVM: ruby-2.6.3) [gem]" level="application" />
|
11
|
-
<orderEntry type="library" scope="PROVIDED" name="chunky_png (v1.3.11, RVM: ruby-2.6.3) [gem]" level="application" />
|
12
|
-
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.3, RVM: ruby-2.6.3) [gem]" level="application" />
|
13
|
-
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.1, RVM: ruby-2.6.3) [gem]" level="application" />
|
14
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.9.0, RVM: ruby-2.6.3) [gem]" level="application" />
|
15
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.9.1, RVM: ruby-2.6.3) [gem]" level="application" />
|
16
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.9.0, RVM: ruby-2.6.3) [gem]" level="application" />
|
17
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.9.1, RVM: ruby-2.6.3) [gem]" level="application" />
|
18
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.9.2, RVM: ruby-2.6.3) [gem]" level="application" />
|
19
|
-
</component>
|
20
|
-
</module>
|
data/.idea/misc.xml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<project version="4">
|
3
|
-
<component name="JavaScriptSettings">
|
4
|
-
<option name="languageLevel" value="ES6" />
|
5
|
-
</component>
|
6
|
-
<component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-2.6.3" project-jdk-type="RUBY_SDK" />
|
7
|
-
</project>
|
data/.idea/modules.xml
DELETED