ruby_matrix_to_svg 0.0.1

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OWI1MjliZWJkZThiOWY0Y2U5MmQyNmQ4YzBkMTZhOTlmNzE5NjhlYw==
5
+ data.tar.gz: !binary |-
6
+ ZjQzMWNlYjBmYjYxODcyNjdlMzMxNjM4ZjQ1NWM0YTlkYjU1MWE3Mg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YmRiYTA1MmI1MWFmNzM2ZWJjOTA1MzIxNDg5NjhkYTM0MjcyOTg1YjY5MjE4
10
+ NWQ3Y2ViNTUzOGQ4OTUxMWU5MmI3NDM3ZTcxOWYyYTU1NjI0MjZmZTBjODI3
11
+ NGJmYmMyODVmNWFjMzRiZGIwZGZiNjIyODFiYjAzYzM1M2FkZTY=
12
+ data.tar.gz: !binary |-
13
+ ZTI3ZjExNWVjMDFkNmI4YWIyZTllMTFkMDMxZjA1OTA0N2E2ZTYwOTgzN2Vj
14
+ Y2E5YTMxM2NhZTQ2MzdhNjJlMDEwNDg0NjBmNmNlNWE0Y2RlY2Q3ZTc3NjEz
15
+ YmI3YWQyYWFkYTBmODljMGEwNzZjZTdkNzlhNjIwZjI2N2IxMzQ=
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .ruby-version
11
+ .ruby-gemset
12
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.6
7
+ - 2.2.4
8
+ before_install:
9
+ - gem install bundler
10
+ notifications:
11
+ email: false
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'coveralls', :require => false
5
+ end
6
+
7
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 santiriera626
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ # RubyMatrixToSvg
2
+
3
+ [![Build Status](https://travis-ci.org/santiriera626/ruby_matrix_to_svg.svg?branch=master)](https://travis-ci.org/santiriera626/ruby_matrix_to_svg)
4
+ [![Coverage Status](https://coveralls.io/repos/github/santiriera626/ruby_matrix_to_svg/badge.svg?branch=master)](https://coveralls.io/github/santiriera626/ruby_matrix_to_svg?branch=master)
5
+ [![Code Climate](https://codeclimate.com/github/santiriera626/ruby_matrix_to_svg/badges/gpa.svg)](https://codeclimate.com/github/santiriera626/ruby_matrix_to_svg)
6
+ [![security](https://hakiri.io/github/santiriera626/ruby_matrix_to_svg/master.svg)](https://hakiri.io/github/santiriera626/ruby_matrix_to_svg/master)
7
+
8
+ RubyMatrixToSvg is a pure Ruby library without any dependencies that allows you to create a svg string from a matrix of colors that you've defined.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'ruby_matrix_to_svg'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install ruby_matrix_to_svg
25
+
26
+ ## Usage
27
+
28
+ Create a svg matrix string from your matrix filled with colors.
29
+
30
+ svg_matrix = RubyMatrixToSvg.matrix_to_svg("ruby_matrix_title", matrix)
31
+
32
+ where **matrix** is the Array of columns and rows filled with colours.
33
+
34
+ Returned String can be used in a simple way in your HTML document settting a size for your image
35
+
36
+ <img src="data:image/svg+xml;utf8, <%= raw(svg_matrix) %>" width="200px">
37
+
38
+ ##Example
39
+
40
+ matrix = [
41
+ ['#fff', '#fff', '#fff'],
42
+ ['#000', '#000', '#000'],
43
+ ['#fff', '#fff', '#fff'],
44
+ ['#000', '#000', '#000']
45
+ ]
46
+
47
+ matrix_string = RubyMatrixToSvg.matrix_to_svg("ruby_matrix_title", matrix)
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/santiriera626/ruby_matrix_to_svg. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
52
+
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task :default => :spec
7
+
8
+ Dir.glob('tasks/**/*.rake').each(&method(:import))
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruby_matrix_to_svg"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,46 @@
1
+ require "ruby_matrix_to_svg/version"
2
+
3
+ module RubyMatrixToSvg
4
+
5
+ # generate the svg string
6
+ #
7
+ # Example:
8
+ # >> matrix_to_svg("svg_image_title" , matrix)
9
+ # => (String)
10
+ #
11
+ # @param title (String) the title of the svg image
12
+ # @param matrix (Array[Array[(String)]]) the colors matrix
13
+
14
+ def self.matrix_to_svg title, matrix
15
+
16
+ # test if params are correct
17
+ raise "title is invalid" if title == nil || title == ''
18
+ raise "matrix is invalid, must be a matrix (array of arrays) of colors" if matrix.class != Array || matrix[0].class != Array
19
+
20
+ # open svg tag
21
+ num_rows = matrix.length
22
+ num_cols = matrix[0].length
23
+
24
+ svg = "<svg xmlns='http://www.w3.org/2000/svg' version='1.1' width='#{num_cols}' height='#{num_rows}'>"
25
+
26
+ # set title
27
+ svg << "<title>#{title}</title>"
28
+
29
+ # background with first color
30
+ svg << "<rect width='100%' height='100%' x='0' y='0' fill='#{matrix[0][0]}' stroke='none' shape-rendering='crispEdges'/>"
31
+
32
+ num_rows.times do |row|
33
+ num_cols.times do |col|
34
+ # draw rect if its color its different than background color
35
+ if matrix[row][col] != matrix[0][0]
36
+ svg << "<rect fill='#{matrix[row][col]}' stroke='none' fill-rule='nonzero' x='#{col}' y='#{row}' width='1' height='1' shape-rendering='crispEdges' />"
37
+ end
38
+ end
39
+ end
40
+
41
+ # close svg tag
42
+ svg << "</svg>"
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,3 @@
1
+ module RubyMatrixToSvg
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruby_matrix_to_svg/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby_matrix_to_svg"
8
+ spec.version = RubyMatrixToSvg::VERSION
9
+ spec.authors = ["santiriera626" , "camumino", "franx0"]
10
+ spec.email = ["santiriera626@gmail.com", "camumino@gmail.com", "francisco.moya.martinez@gmail.com"]
11
+
12
+ spec.summary = %q{Gem to create a svg string from a matrix of colors.}
13
+ spec.description = <<-EOT
14
+ RubyMatrixToSvg is a pure Ruby library without any dependencies that allows you to create a svg string from a matrix of colors that you've defined
15
+ EOT
16
+ spec.homepage = "https://github.com/santiriera626/ruby_matrix_to_svg"
17
+ spec.license = "MIT"
18
+
19
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
20
+ # delete this section to allow pushing this gem to any host.
21
+ if spec.respond_to?(:metadata)
22
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
25
+ end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.5"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency 'rspec', "~> 3.4.0"
35
+
36
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_matrix_to_svg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - santiriera626
8
+ - camumino
9
+ - franx0
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2016-03-30 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.5'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: '1.5'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: '10.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: '10.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rspec
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: 3.4.0
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 3.4.0
57
+ description: ! ' RubyMatrixToSvg is a pure Ruby library without any dependencies
58
+ that allows you to create a svg string from a matrix of colors that you''ve defined
59
+
60
+ '
61
+ email:
62
+ - santiriera626@gmail.com
63
+ - camumino@gmail.com
64
+ - francisco.moya.martinez@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .rspec
71
+ - .travis.yml
72
+ - CODE_OF_CONDUCT.md
73
+ - Gemfile
74
+ - LICENSE.txt
75
+ - README.md
76
+ - Rakefile
77
+ - bin/console
78
+ - bin/setup
79
+ - lib/ruby_matrix_to_svg.rb
80
+ - lib/ruby_matrix_to_svg/version.rb
81
+ - ruby_matrix_to_svg.gemspec
82
+ homepage: https://github.com/santiriera626/ruby_matrix_to_svg
83
+ licenses:
84
+ - MIT
85
+ metadata:
86
+ allowed_push_host: https://rubygems.org
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.4.3
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Gem to create a svg string from a matrix of colors.
107
+ test_files: []