mosaiq 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 544b21c20826297ee626f191b5bd7169f8a82013ab9c35b45554d78c42a9981a
4
- data.tar.gz: fa00e04db556682405c99381b434f416a711e2a8318cdc0dec69efabce67cd5a
3
+ metadata.gz: daffaca74dc4a1eddd2fe004ba2260ccea7e3b49d5059d6020dc0e2a655cfad1
4
+ data.tar.gz: 426bedae6e90f2c174ca23520abb4642329b2c75808872542feee62bd41c5a77
5
5
  SHA512:
6
- metadata.gz: f7592c0ca8158c951ae14e07f185fd6ce8e233135a7227e46d4bac449601ed35cc7ebba0820eb14e6ad03fa6ba69c2f9685f085ded8bc9e3daadfcabf1044647
7
- data.tar.gz: e814b8e37c71066ec0d159887e9a0f9d4c858f95549cd5ecac10399f21f14d40a107f43d8c2364486e57435d6c36d386917f5c1cee47e7a4b438da7dcc65e7a9
6
+ metadata.gz: 8a966a5c15fe843ca08e98983d03b101130805c57952bdd58a87e273e37635427a9e9ea2a49a9e5131a41a0d51e43da56dc0599cf456c979d3c82c2715e2790c
7
+ data.tar.gz: 2568ab57f9626317ef60ad09da4162d5961ffc0f3a7c200b37b36a90ec46ad74512ee3f22df12a7c814dfdfa5befd201a6708ad5956c421c65093ac8650e209d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mosaiq (0.1.2)
4
+ mosaiq (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -11,10 +11,7 @@ GEM
11
11
  docile (1.3.2)
12
12
  jaro_winkler (1.5.3)
13
13
  json (2.2.0)
14
- mini_portile2 (2.4.0)
15
14
  minitest (5.12.2)
16
- nokogiri (1.10.4)
17
- mini_portile2 (~> 2.4.0)
18
15
  parallel (1.18.0)
19
16
  parser (2.6.5.0)
20
17
  ast (~> 2.4.0)
@@ -43,7 +40,6 @@ DEPENDENCIES
43
40
  byebug
44
41
  minitest (~> 5.0)
45
42
  mosaiq!
46
- nokogiri
47
43
  rake (~> 10.0)
48
44
  rubocop
49
45
  simplecov
data/README.md CHANGED
@@ -27,11 +27,11 @@ Or install it yourself as:
27
27
  Base usage:
28
28
 
29
29
  ```ruby
30
- image = Mosaiq::Image.new(width: 3, height: 4, colors: %w[red green blue])
30
+ image = Mosaiq::Image.new(width: 3, height: 4, palette: %w[red green blue])
31
31
  ```
32
32
 
33
33
  * Unit of `width` and `height` is pixels
34
- * `colors` is an `Array` of color names. Any valid HTML color will work. There are also predefined color "Palettes", [see below](#palette).
34
+ * `palette` is an `Array` of color names. Any valid HTML color will work. There are also [predefined Palettes](#palette).
35
35
 
36
36
 
37
37
  ### SVG
@@ -52,13 +52,13 @@ which looks like this when saved to a file
52
52
 
53
53
  ## Palette
54
54
 
55
- There are three predefined "Palettes" of colors:
55
+ There are three predefined Palettes:
56
56
 
57
57
  | Palette | Example | Result |
58
58
  |--------------------|--------------------------------------------------------------------------------------|-------------------------------------------------------------------------|
59
- | `black_and_white` | `Mosaiq::Image.new(width: 10, height: 5, colors: Mosaiq::Palette::black_and_white)` | ![Example black_and_white](./documentation/example_black_and_white.svg) |
60
- | `grays` | `Mosaiq::Image.new(width: 10, height: 5, colors: Mosaiq::Palette::grays)` | ![Example grays](./documentation/example_grays.svg) |
61
- | `random_colors(n)` | `Mosaiq::Image.new(width: 10, height: 5, colors: Mosaiq::Palette::random_colors(8))` | ![Example random_colors](./documentation/example_random_colors_8.svg) |
59
+ | `black_and_white` | `Mosaiq::Image.new(width: 10, height: 5, palette: Mosaiq::Palette::black_and_white)` | ![Example black_and_white](./documentation/example_black_and_white.svg) |
60
+ | `grays` | `Mosaiq::Image.new(width: 10, height: 5, palette: Mosaiq::Palette::grays)` | ![Example grays](./documentation/example_grays.svg) |
61
+ | `random_colors(n)` | `Mosaiq::Image.new(width: 10, height: 5, palette: Mosaiq::Palette::random_colors(8))` | ![Example random_colors](./documentation/example_random_colors_8.svg) |
62
62
 
63
63
 
64
64
  ## Development
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'rake/testtask'
6
6
  Rake::TestTask.new(:test) do |t|
7
7
  t.libs << 'test'
8
8
  t.libs << 'lib'
9
- t.test_files = FileList['test/**/*_test.rb']
9
+ t.test_files = FileList['test/support/**/*.rb'] + FileList['test/**/*_test.rb']
10
10
  end
11
11
 
12
12
  task default: :test
data/lib/mosaiq/errors.rb CHANGED
@@ -9,10 +9,10 @@ module Errors
9
9
  end
10
10
  end
11
11
 
12
- # Raised when colors argument is empty
13
- class InvalidColorsArgument < StandardError
12
+ # Raised when palette argument is empty
13
+ class InvalidPaletteArgument < StandardError
14
14
  def initialize
15
- super "Argument 'colors' should not be empty. Please provide an array with color names."
15
+ super "Argument 'palette' should not be empty. Please provide an array with color names."
16
16
  end
17
17
  end
18
18
  end
data/lib/mosaiq/image.rb CHANGED
@@ -5,10 +5,12 @@ require 'mosaiq/svg'
5
5
  module Mosaiq
6
6
  # Main class to create a Mosaiq Image
7
7
  class Image
8
- def initialize(width:, height:, colors: Palette.black_and_white)
8
+ attr_reader :canvas
9
+
10
+ def initialize(width:, height:, palette: Palette.black_and_white)
9
11
  @width = read_positive_integer(width: width)
10
12
  @height = read_positive_integer(height: height)
11
- @colors = read_colors(colors)
13
+ @palette = read_palette(palette)
12
14
 
13
15
  build_canvas
14
16
  end
@@ -21,7 +23,7 @@ module Mosaiq
21
23
 
22
24
  def build_canvas
23
25
  total = @width * @height
24
- all_tiles = Array.new(total).map { @colors.sample }
26
+ all_tiles = Array.new(total).map { @palette.sample }
25
27
  @canvas = all_tiles.each_slice(@width).collect(&:itself)
26
28
  end
27
29
 
@@ -33,10 +35,10 @@ module Mosaiq
33
35
  raise Mosaiq::InvalidDimensionArgument.new(key, value)
34
36
  end
35
37
 
36
- def read_colors(colors)
37
- return colors unless colors.empty?
38
+ def read_palette(palette)
39
+ return palette unless palette.empty?
38
40
 
39
- raise Mosaiq::InvalidColorsArgument
41
+ raise Mosaiq::InvalidPaletteArgument
40
42
  end
41
43
  end
42
44
  end
data/lib/mosaiq/svg.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'base64'
4
+
3
5
  module Mosaiq
4
6
  # Generate SVG version of the Mosaiq
5
7
  class Svg
@@ -10,14 +12,25 @@ module Mosaiq
10
12
  end
11
13
 
12
14
  def raw
13
- %(#{svg_header} #{svg_body}).tr("\n", '').gsub(/ +/, ' ')
15
+ %(#{svg_header}#{svg_body}).delete("\n").gsub(/ +/, ' ')
16
+ end
17
+
18
+ def to_base64
19
+ Base64.encode64(raw).delete("\n")
14
20
  end
15
21
 
16
22
  private
17
23
 
18
24
  def svg_header
19
- %(<?xml version="1.0" encoding="UTF-8"?>
20
- <!DOCTYPE svg
25
+ "#{svg_header_xml}#{svg_header_doctype}"
26
+ end
27
+
28
+ def svg_header_xml
29
+ %(<?xml version="1.0" encoding="UTF-8"?>)
30
+ end
31
+
32
+ def svg_header_doctype
33
+ %(<!DOCTYPE svg
21
34
  PUBLIC
22
35
  "-//W3C//DTD SVG 1.1//EN"
23
36
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mosaiq
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
data/mosaiq.gemspec CHANGED
@@ -35,7 +35,6 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency 'bundler', '~> 2.0'
36
36
  spec.add_development_dependency 'byebug'
37
37
  spec.add_development_dependency 'minitest', '~> 5.0'
38
- spec.add_development_dependency 'nokogiri'
39
38
  spec.add_development_dependency 'rake', '~> 10.0'
40
39
  spec.add_development_dependency 'rubocop'
41
40
  spec.add_development_dependency 'simplecov'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mosaiq
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
  - lxxxvi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-31 00:00:00.000000000 Z
11
+ date: 2019-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
- - !ruby/object:Gem::Dependency
56
- name: nokogiri
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rake
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -160,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
146
  - !ruby/object:Gem::Version
161
147
  version: '0'
162
148
  requirements: []
163
- rubygems_version: 3.0.6
149
+ rubygems_version: 3.0.3
164
150
  signing_key:
165
151
  specification_version: 4
166
152
  summary: Mosaiq generates images of randomly colored pixels