polygonfy 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 75415e890dff458963065f8d99b0a6087ec1259e
4
+ data.tar.gz: 1bb8b14cbf46db3519c5a49f3d8cdf768c732e59
5
+ SHA512:
6
+ metadata.gz: 81f235e862dc9685e844e495a7ccd08e9b6b643596512aeb703a867b39c89e528082d99eac48a8c44b21d9a02c7ba5455524376e2c0dcb7877626730d5f3dad4
7
+ data.tar.gz: ac99be018e02e715bfc209f26a59a981de24c1b1e0f5700ca618be7c69ddcb76d32494210befd06ff8df653a575b2a78f5efae3a4c62aca7a6aca41f454ebc61
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in polygonfy.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Alexandre Magro
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.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Polygonfy
2
+
3
+ Draw an SVG polygon easily from the command line.
4
+
5
+ ## Installation
6
+
7
+ $ gem install polygonfy
8
+
9
+ ## Usage
10
+
11
+ format:
12
+
13
+ $ polygonfy FILENAME ID,X,Y ID,X,Y ID,X,Y ...
14
+
15
+ in terminal:
16
+
17
+ $ polygonfy mymap.svg 1,00,0 2,100.50,100.50 3,0,200.70
18
+
19
+ 1. "mymap.svg" is output file;
20
+ 2. others parameters are points in (ID,X,Y) format
21
+
22
+ You can also use with pipe operator:
23
+
24
+ $ myowntask | polygonfy mymap.svg
25
+
26
+ 1. Since "myowntask" returns formated points in STDOUT
27
+
28
+ ## License
29
+
30
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
31
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "polygonfy"
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
data/bin/polygonfy ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'polygonfy'
4
+
5
+ Polygonfy::run
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module Polygonfy
2
+ class Point < Struct.new(:id, :x, :y); end
3
+ end
@@ -0,0 +1,3 @@
1
+ module Polygonfy
2
+ VERSION = "0.1.1"
3
+ end
data/lib/polygonfy.rb ADDED
@@ -0,0 +1,62 @@
1
+ require "polygonfy/version"
2
+ require "polygonfy/Point"
3
+ require "nokogiri"
4
+
5
+ module Polygonfy
6
+ MARGIN = 12
7
+ STYLES = {
8
+ polygon: "fill:#4f9bff; stroke:#216cce; stroke-width:1; opacity:0.5",
9
+ circle: "fill:orange"
10
+ }
11
+
12
+ def self.point_title(array, i)
13
+ prev_point = array[i - 1].id
14
+ next_point = array[(i + 1) % array.size].id
15
+ curr_point = "#{array[i].x}, #{array[i].y}"
16
+
17
+ "#{prev_point} (#{curr_point}) #{next_point}"
18
+ end
19
+
20
+ def self.run
21
+ if ARGV.length == 0
22
+ puts "Use: polygonfy filename [id,x,y] [id,x,y] [..]"
23
+ return
24
+ end
25
+
26
+ filename = ARGV[0]
27
+
28
+ points = ARGV.length > 1 ? ARGV.drop(1) : STDIN.readline.split(' ')
29
+
30
+ points.map! do |p|
31
+ id, x, y = p.split(',')
32
+ Point.new(id, x.to_i + MARGIN, y.to_i + MARGIN)
33
+ end
34
+
35
+ xmlns = "http://www.w3.org/2000/svg"
36
+ width = points.map(&:x).max + MARGIN
37
+ height = points.map(&:y).max + MARGIN
38
+
39
+ polygon_points = points.map { |p| "#{p.x},#{p.y}" }.join(' ')
40
+
41
+ builder = Nokogiri::XML::Builder.new do |xml|
42
+ xml.svg(xmlns: xmlns, width: width, height: height) {
43
+ xml.polygon(style: STYLES[:polygon], points: polygon_points)
44
+ xml.g {
45
+ points.each_with_index do |p, i|
46
+ xml.circle(style: STYLES[:circle], cx: p.x, cy: p.y, r: "12")
47
+ xml.text_(x: p.x, y: p.y + 5, 'text-anchor': 'middle') {
48
+ xml.text(p.id)
49
+ xml.title {
50
+ xml.text(point_title(points, i))
51
+ }
52
+ }
53
+ end
54
+ }
55
+ }
56
+ end
57
+
58
+ File.open(filename, 'w') do |f|
59
+ f.write(builder.to_xml)
60
+ end
61
+ end
62
+ end
data/polygonfy.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'polygonfy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "polygonfy"
8
+ spec.version = Polygonfy::VERSION
9
+ spec.authors = ["Alexandre Magro"]
10
+ spec.email = ["alx.magro@gmail.com"]
11
+ spec.homepage = "https://github.com/alexandremagro/polygonfy"
12
+ spec.summary = "GDraw an SVG polygon easily from the command line"
13
+ spec.description = "Draw an SVG polygon easily from the command line"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.executables = ["polygonfy"]
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "nokogiri", "~> 1.7.1"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: polygonfy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexandre Magro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.7.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.7.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Draw an SVG polygon easily from the command line
70
+ email:
71
+ - alx.magro@gmail.com
72
+ executables:
73
+ - polygonfy
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/polygonfy
86
+ - bin/setup
87
+ - lib/polygonfy.rb
88
+ - lib/polygonfy/Point.rb
89
+ - lib/polygonfy/version.rb
90
+ - polygonfy.gemspec
91
+ homepage: https://github.com/alexandremagro/polygonfy
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.5.1
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: GDraw an SVG polygon easily from the command line
115
+ test_files: []