monsterid 0.4.0 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG +5 -0
  3. data/VERSION +1 -1
  4. data/lib/monsterid.rb +53 -59
  5. metadata +13 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b70b638dc77e81b18130ee84c99622d7b672ebe5
4
- data.tar.gz: cdf780b925ce81508d0c7f94da3172ddc6726c7a
2
+ SHA256:
3
+ metadata.gz: 244ae4b3aae8ef433d3258aa77852dc093187b2869be99268579948577b78830
4
+ data.tar.gz: d2b8a65efaf21e61c8c8c3112450d718b258eaa214dcc2ea96718612d3bd9453
5
5
  SHA512:
6
- metadata.gz: b0913884f584389ef6e4ef73c6c21b837bd2843310209b9d33faa3ce74d9499d4753f5fff841b76d712e84cdda27e57ee88ab0489ce86f585d74b13699f9b740
7
- data.tar.gz: 97a52426c835a05a2c5a55001829b50b17274845b9268e59bc68efa15b95d337316794a5d45edbdf8ef3c212009dec9f98cc25b2f454bc9540acd1f68504dd28
6
+ metadata.gz: dcd9716d34441fc4f06fbe5ed4b9b494eef7630bf5961b9379e1a0070da54827d7e7c844e17ef08583c4a5d3a5900d56b529c724096dc7681a5cc0994debe37d
7
+ data.tar.gz: 1aace8a281450f025377171e522cb272fec4e58b07c9973389a7e429d43246a7e6283b53934d36e1c2fbdfa08cc398799e0564e266ddcb18fd45a4e00f2530ae
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 0.4.2:
2
+ - Dependency bumps due to security issues
3
+ - Rubocop style fixes
4
+ - String freeze
5
+
1
6
  0.4.0:
2
7
  - Depend on ChunkyPNG, not OilyPNG, thus not requiring a C extension
3
8
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.2
data/lib/monsterid.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Load oily_png if available, otherwise default to pure ruby chunky_png
2
4
  begin
3
5
  require 'oily_png'
@@ -15,112 +17,110 @@ class MonsterID
15
17
  'legs_4.png', 'legs_S8.png', 'legs_S11.png', 'mouth_5.png',
16
18
  'mouth_8.png', 'mouth_S1.png', 'mouth_S3.png', 'mouth_2.png',
17
19
  'eyes_13.png', 'legs_S13.png', 'mouth_S7.png'
18
- ]
20
+ ].freeze
19
21
  BODY_COLOR_PARTS = [
20
22
  'arms_S8.png', 'legs_S5.png',
21
23
  'mouth_S5.png', 'mouth_S4.png'
22
- ]
24
+ ].freeze
23
25
  SPECIFIC_COLOR_PARTS = {
24
- 'arms_S2.png' => [0, 200],
25
- 'hair_S6.png' => [0, 200],
26
- 'mouth_9.png' => [0, 200],
27
- 'mouth_6.png' => [0, 200],
26
+ 'arms_S2.png' => [0, 200],
27
+ 'hair_S6.png' => [0, 200],
28
+ 'mouth_9.png' => [0, 200],
29
+ 'mouth_6.png' => [0, 200],
28
30
  'mouth_S2.png' => [0, 200]
29
- }
30
-
31
+ }.freeze
32
+
31
33
  PARTS = {
32
- :arms => [
34
+ arms: [
33
35
  'arms_1.png', 'arms_2.png', 'arms_3.png', 'arms_4.png', 'arms_5.png',
34
36
  'arms_S1.png', 'arms_S2.png', 'arms_S3.png', 'arms_S4.png', 'arms_S5.png',
35
37
  'arms_S6.png', 'arms_S7.png', 'arms_S8.png', 'arms_S9.png'
36
38
  ],
37
- :body => [
39
+ body: [
38
40
  'body_1.png', 'body_2.png', 'body_3.png', 'body_4.png', 'body_5.png',
39
41
  'body_6.png', 'body_7.png', 'body_8.png', 'body_9.png', 'body_10.png',
40
42
  'body_11.png', 'body_12.png', 'body_13.png', 'body_14.png', 'body_15.png',
41
43
  'body_S1.png', 'body_S2.png', 'body_S3.png', 'body_S4.png', 'body_S5.png'
42
44
  ],
43
- :eyes => [
45
+ eyes: [
44
46
  'eyes_1.png', 'eyes_2.png', 'eyes_3.png', 'eyes_4.png', 'eyes_5.png',
45
47
  'eyes_6.png', 'eyes_7.png', 'eyes_8.png', 'eyes_9.png', 'eyes_10.png',
46
48
  'eyes_11.png', 'eyes_12.png', 'eyes_13.png', 'eyes_14.png', 'eyes_15.png',
47
49
  'eyes_S1.png', 'eyes_S2.png', 'eyes_S3.png', 'eyes_S4.png', 'eyes_S5.png'
48
50
  ],
49
- :hair => [
51
+ hair: [
50
52
  'hair_1.png', 'hair_2.png', 'hair_3.png', 'hair_4.png', 'hair_5.png',
51
53
  'hair_S1.png', 'hair_S2.png', 'hair_S3.png', 'hair_S4.png', 'hair_S5.png',
52
54
  'hair_S6.png', 'hair_S7.png'
53
55
  ],
54
- :legs => [
56
+ legs: [
55
57
  'legs_1.png', 'legs_2.png', 'legs_3.png', 'legs_4.png', 'legs_5.png',
56
58
  'legs_S1.png', 'legs_S10.png', 'legs_S11.png', 'legs_S12.png',
57
- 'legs_S13.png', 'legs_S2.png', 'legs_S3.png', 'legs_S4.png',
59
+ 'legs_S13.png', 'legs_S2.png', 'legs_S3.png', 'legs_S4.png',
58
60
  'legs_S5.png', 'legs_S6.png', 'legs_S7.png', 'legs_S8.png', 'legs_S9.png'
59
61
  ],
60
- :mouth => [
62
+ mouth: [
61
63
  'mouth_1.png', 'mouth_2.png', 'mouth_3.png', 'mouth_4.png', 'mouth_5.png',
62
64
  'mouth_6.png', 'mouth_7.png', 'mouth_8.png', 'mouth_9.png', 'mouth_10.png',
63
65
  'mouth_S1.png', 'mouth_S2.png', 'mouth_S3.png', 'mouth_S4.png', 'mouth_S5.png',
64
66
  'mouth_S6.png', 'mouth_S7.png'
65
67
  ]
66
- }
67
-
68
+ }.freeze
69
+
68
70
  # Remove body 12 for now, doesn't look good
69
- PARTS[:body].delete( 'body_12.png' )
70
-
71
+ PARTS[:body].delete('body_12.png')
72
+
71
73
  # Test color set [hue, sat]
72
74
  COLORS = [
73
75
  [8, 255], [160, 64], [8, 127], [184, 255],
74
76
  [24, 191], [208, 191], [40, 255], [208, 64],
75
77
  [48, 64], [248, 191], [72, 127], [272, 64],
76
78
  [128, 255], [312, 191], [160, 255], [336, 255]
77
- ]
78
-
79
+ ].freeze
80
+
79
81
  def initialize(seed, size = 120)
80
82
  @id = Digest::SHA1.hexdigest seed.to_s
81
-
83
+
82
84
  parts = {
83
- :legs => {
84
- :part => PARTS[:legs ][@id[0, 2].hex % PARTS[:legs ].length],
85
- :color => COLORS[@id[2, 2].hex % COLORS.length]
85
+ legs: {
86
+ part: PARTS[:legs][@id[0, 2].hex % PARTS[:legs].length],
87
+ color: COLORS[@id[2, 2].hex % COLORS.length]
86
88
  },
87
- :hair => {
88
- :part => PARTS[:hair ][@id[4, 2].hex % PARTS[:hair ].length],
89
- :color => COLORS[@id[6, 2].hex % COLORS.length]
89
+ hair: {
90
+ part: PARTS[:hair][@id[4, 2].hex % PARTS[:hair].length],
91
+ color: COLORS[@id[6, 2].hex % COLORS.length]
90
92
  },
91
- :arms => {
92
- :part => PARTS[:arms ][@id[8, 2].hex % PARTS[:arms ].length],
93
- :color => COLORS[@id[10, 2].hex % COLORS.length]
93
+ arms: {
94
+ part: PARTS[:arms][@id[8, 2].hex % PARTS[:arms].length],
95
+ color: COLORS[@id[10, 2].hex % COLORS.length]
94
96
  },
95
- :body => {
96
- :part => PARTS[:body ][@id[12, 2].hex % PARTS[:body ].length],
97
- :color => COLORS[@id[14, 2].hex % COLORS.length]
97
+ body: {
98
+ part: PARTS[:body][@id[12, 2].hex % PARTS[:body].length],
99
+ color: COLORS[@id[14, 2].hex % COLORS.length]
98
100
  },
99
- :eyes => {
100
- :part => PARTS[:eyes ][@id[16, 2].hex % PARTS[:eyes ].length],
101
- :color => COLORS[@id[18, 2].hex % COLORS.length]
101
+ eyes: {
102
+ part: PARTS[:eyes][@id[16, 2].hex % PARTS[:eyes].length],
103
+ color: COLORS[@id[18, 2].hex % COLORS.length]
102
104
  },
103
- :mouth => {
104
- :part => PARTS[:mouth][@id[20, 2].hex % PARTS[:mouth].length],
105
- :color => COLORS[@id[22, 2].hex % COLORS.length]
105
+ mouth: {
106
+ part: PARTS[:mouth][@id[20, 2].hex % PARTS[:mouth].length],
107
+ color: COLORS[@id[22, 2].hex % COLORS.length]
106
108
  }
107
109
  }
108
-
110
+
109
111
  @monster = ChunkyPNG::Image.new(120, 120, ChunkyPNG::Color::TRANSPARENT)
110
-
112
+
111
113
  parts.each do |_, part|
112
114
  path = File.join(File.dirname(__FILE__), 'parts', part[:part])
113
115
  partimg = ChunkyPNG::Image.from_file(path)
114
-
116
+
115
117
  if BODY_COLOR_PARTS.include? part[:part]
116
118
  part[:color] = parts[:body][:color]
117
119
  elsif SPECIFIC_COLOR_PARTS.include? part[:part]
118
120
  part[:color] = SPECIFIC_COLOR_PARTS[part[:part]]
119
121
  end
120
-
121
- unless WHITE_PARTS.include? part[:part]
122
- partimg = colorise(partimg, part[:color][0], part[:color][1])
123
- end
122
+
123
+ partimg = colorise(partimg, part[:color][0], part[:color][1]) unless WHITE_PARTS.include? part[:part]
124
124
 
125
125
  @monster.compose!(partimg)
126
126
  end
@@ -139,30 +139,24 @@ class MonsterID
139
139
  def to_datastream
140
140
  @monster.to_datastream
141
141
  end
142
-
143
- def id
144
- @id
145
- end
142
+
143
+ attr_reader :id
146
144
 
147
145
  def to_data_url
148
146
  @monster.to_data_url
149
147
  end
150
-
148
+
151
149
  def inspect
152
150
  "#<#{self.class.name}:#{object_id} id: #{@id}>"
153
151
  end
154
152
 
155
153
  private
156
154
 
157
- def colorise(img, hue, sat = 255)
158
- sat = sat.to_f / 255 # ChunkyPNG uses sat from 0.0 to 1.0
155
+ def colorise(img, h, s = 255)
156
+ s = s.to_f / 255 # ChunkyPNG uses sat from 0.0 to 1.0
159
157
 
160
158
  img.pixels.map! do |px|
161
- h, s, v, a = ChunkyPNG::Color.to_hsv(px, true)
162
-
163
- h = hue
164
- s = sat
165
-
159
+ _, _, v, a = ChunkyPNG::Color.to_hsv(px, true)
166
160
  ChunkyPNG::Color.from_hsv(h, s, v, a)
167
161
  end
168
162
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monsterid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Knut Aldrin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-04 00:00:00.000000000 Z
11
+ date: 2021-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chunky_png
@@ -16,48 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 1.3.7
19
+ version: '1.4'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '1.3'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 1.3.7
26
+ version: '1.4'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: bundler
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: '1.0'
33
+ version: '2.1'
40
34
  type: :development
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
38
  - - "~>"
45
39
  - !ruby/object:Gem::Version
46
- version: '1.0'
40
+ version: '2.1'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: rubocop
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: 0.44.1
47
+ version: '1.14'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
52
  - - "~>"
59
53
  - !ruby/object:Gem::Version
60
- version: 0.44.1
54
+ version: '1.14'
61
55
  description: Port/rework of the php script, with new monsters snatched from the WP
62
56
  plugin
63
57
  email: knutaldrin@gmail.com
@@ -178,7 +172,7 @@ homepage: https://github.com/knutaldrin/monsterid
178
172
  licenses:
179
173
  - CC-BY-4.0
180
174
  metadata: {}
181
- post_install_message:
175
+ post_install_message:
182
176
  rdoc_options: []
183
177
  require_paths:
184
178
  - lib
@@ -186,16 +180,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
180
  requirements:
187
181
  - - ">="
188
182
  - !ruby/object:Gem::Version
189
- version: '0'
183
+ version: '2.0'
190
184
  required_rubygems_version: !ruby/object:Gem::Requirement
191
185
  requirements:
192
186
  - - ">="
193
187
  - !ruby/object:Gem::Version
194
188
  version: '0'
195
189
  requirements: []
196
- rubyforge_project:
197
- rubygems_version: 2.6.11
198
- signing_key:
190
+ rubygems_version: 3.2.15
191
+ signing_key:
199
192
  specification_version: 4
200
193
  summary: Generates tiny little monsters to discern users.
201
194
  test_files: []