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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e198c12ffff3f2fa94e8799a43c4b995dcd7a2e07d1cf7959636cc19772d714
4
- data.tar.gz: 922d2e430a4993e6e8362fcd45764f48eb4f6dc77c37fbbf4443d947ea56dddb
3
+ metadata.gz: 7c76cb538a8f25b0af5313d79eb8a37c8a501f26a539f8d05e12a80f54c957c5
4
+ data.tar.gz: 44e44d8ade326b33fc205fa3d097c63ba6473316379046b1163b7edd68522642
5
5
  SHA512:
6
- metadata.gz: 0eb01091b30fae43c07a4f983483f5aab04d2a354e50bf13ae9c761e13b272aec30dd79db52f3a8fa5c1eb19a764b7bfb054911512128f2bf865d09204df71c5
7
- data.tar.gz: c48bf374e3d3ae6a83981d7bc371a9031d1a77edc939d68c447eabf00e7375f253ad1e1c6941d3cb2f00d4d3ef1cee51a5163721a02f23b74da655e5daea3644
6
+ metadata.gz: ab491d24ee164d4aa48b4fdec1305f532eb4cf98b26fb99ff5c2e1aa94082d37e22943ffaa433d1cc3775e45c3d968894559f80f2d1788b7abebc7884812b912
7
+ data.tar.gz: 5c9439a92e25badeea39899a405bdf62d065fc1914b2c239f40f5341d7d937c318a7c3cd4da76bc647ce68a9c983579a302952f6adfa127ed1ed902134aa690a
data/.gitignore CHANGED
@@ -7,6 +7,7 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  /tmp.png
10
+ /.idea/
10
11
 
11
12
  # rspec failure tracking
12
13
  .rspec_status
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- idecon (0.1.1)
4
+ idecon (0.1.2)
5
5
  chunky_png
6
6
 
7
7
  GEM
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Idecon
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
data/lib/idecon.rb CHANGED
@@ -8,10 +8,15 @@ module Idecon
8
8
  class Error < StandardError; end
9
9
 
10
10
  class Identicon
11
- def initialize(user_name, path)
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 = [0, 0, 0]
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 = if (0..4).include?(c) || ('a'..'m').include?(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
- @color = @hash[23..32].scan(/([\w\d])([\w\d])([\w\d])/).map do |arr|
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 * (c.to_i(36) + 10).to_s[1].to_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(250, 250, ChunkyPNG::Color.rgb(0, 0, 0))
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
- @image.rect(square[0] * 50, square[1] * 50,
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.2
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-29 00:00:00.000000000 Z
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
@@ -1,3 +0,0 @@
1
-
2
- # Default ignored files
3
- /workspace.xml
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
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/idecon.iml" filepath="$PROJECT_DIR$/.idea/idecon.iml" />
6
- </modules>
7
- </component>
8
- </project>
data/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
- </component>
6
- </project>