inch-badge 0.1.0

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: d4afd78a2a4fa4daaf8b51eede53f73c978b2a2f
4
+ data.tar.gz: 144a2d5bea028f9b9513ac7a38b55b6de168e3e6
5
+ SHA512:
6
+ metadata.gz: 79222631950c6069edc8c2f00c6a3f11e9976247f2f0096a7d2031004822cfc3e80a3d3c20f584030105d49b72e6167d42f936345aa1d6930e4d41420ee542ee
7
+ data.tar.gz: aa86ee54b5970e96be9c53dd49dd9b1454d6345ea8ea8be94baa5e28120e5f8f6887e5e511c56910bb77e70b58c2696e6bff6d4934beff73a4f07a1bd025abb6
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.png
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ inch-badge
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in inch-badge.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 René Föhring
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Inch::Badge
2
+
3
+ Rubygem used to generate badges for Inch
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'inch-badge'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install inch-badge
18
+
19
+ ## Usage
20
+
21
+ ### Shell
22
+
23
+ $ inch-badge FILENAME A B C U
24
+
25
+ Example:
26
+
27
+ $ inch-badge example.png 300 21 12 316
28
+
29
+ ### Ruby
30
+
31
+ ```ruby
32
+ Inch::Badge::Image.new("example.png", [300, 21, 12, 316]).save
33
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/assets/bg.png ADDED
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/bin/inch-badge ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # @return [String] the path to the 'lib' directory of Inch
4
+ def find_lib_path
5
+ path = __FILE__
6
+ while File.symlink?(path)
7
+ path = File.expand_path(File.readlink(path), File.dirname(path))
8
+ end
9
+ File.join(File.dirname(File.expand_path(path)), '..', 'lib')
10
+ end
11
+
12
+ $LOAD_PATH.unshift(find_lib_path)
13
+
14
+ require 'inch/badge'
15
+
16
+ if ARGV.size != 5
17
+ order = Inch::Badge::Config::GRADE_ORDER.join(' ')
18
+ puts "Usage: inch-badge FILENAME #{order}"
19
+ exit 1
20
+ end
21
+
22
+ Inch::Badge::Image.new(ARGV.shift, ARGV).save
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'inch/badge/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "inch-badge"
8
+ spec.version = Inch::Badge::VERSION
9
+ spec.authors = ["René Föhring"]
10
+ spec.email = ["rf@bamaru.de"]
11
+ spec.summary = %q{Rubygem used to generate badges for Inch}
12
+ spec.description = %q{Rubygem used to generate badges for Inch}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "chunky_png"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,14 @@
1
+ module Inch
2
+ module Badge
3
+ class Config
4
+ GRADE_ORDER = %w(A B C U)
5
+ SECTION_WIDTH = 40 # px
6
+
7
+ class << self
8
+ def image_path(filename)
9
+ File.join(Badge::ROOT, "assets", filename)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,62 @@
1
+ require 'chunky_png'
2
+
3
+ module Inch
4
+ module Badge
5
+ class GradeSection < Struct.new(:name, :size, :overall)
6
+ def prefix(x)
7
+ if x == 0
8
+ "begin"
9
+ elsif x == section_width - 1
10
+ "end"
11
+ else
12
+ "body"
13
+ end
14
+ end
15
+
16
+ def width
17
+ ((size / overall.to_f) * section_width).round
18
+ end
19
+
20
+ def section_width
21
+ Config::SECTION_WIDTH
22
+ end
23
+ end
24
+
25
+ class Image
26
+ def initialize(filename, numbers)
27
+ @filename = filename
28
+ @numbers = numbers.map(&:to_i)
29
+ @overall = @numbers.inject(0, :+)
30
+ end
31
+
32
+ def save
33
+ @grades = Config::GRADE_ORDER.map.with_index do |name, index|
34
+ GradeSection.new(name, @numbers[index], @overall)
35
+ end
36
+
37
+ base_image = ChunkyPNG::Image.from_file( Config.image_path('bg.png') )
38
+
39
+ x = 0
40
+ @grades.each do |grade|
41
+ grade.width.times do |i|
42
+ if x < grade.section_width
43
+ badge = load_image( Config.image_path("grade-#{grade.name}-#{grade.prefix(x)}.png") )
44
+ base_image.compose!(badge, 34+x, 0)
45
+ end
46
+ x += 1
47
+ end
48
+ end
49
+
50
+ base_image.save(@filename, :fast_rgba)
51
+ end
52
+
53
+ private
54
+
55
+ def load_image(filename)
56
+ @cache ||= {}
57
+ @cache[filename] ||= ChunkyPNG::Image.from_file(filename)
58
+ @cache[filename]
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,5 @@
1
+ module Inch
2
+ module Badge
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
data/lib/inch/badge.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'inch/badge/config'
2
+ require 'inch/badge/image'
3
+ require 'inch/badge/version'
4
+
5
+ module Inch
6
+ module Badge
7
+ ROOT = File.join( File.dirname(__FILE__), '..', '..' )
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inch-badge
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - René Föhring
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: chunky_png
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Rubygem used to generate badges for Inch
56
+ email:
57
+ - rf@bamaru.de
58
+ executables:
59
+ - inch-badge
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".ruby-gemset"
65
+ - ".ruby-version"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - assets/bg.png
71
+ - assets/grade-A-begin.png
72
+ - assets/grade-A-body.png
73
+ - assets/grade-A-end.png
74
+ - assets/grade-B-begin.png
75
+ - assets/grade-B-body.png
76
+ - assets/grade-B-end.png
77
+ - assets/grade-C-begin.png
78
+ - assets/grade-C-body.png
79
+ - assets/grade-C-end.png
80
+ - assets/grade-U-begin.png
81
+ - assets/grade-U-body.png
82
+ - assets/grade-U-end.png
83
+ - bin/inch-badge
84
+ - inch-badge.gemspec
85
+ - lib/inch/badge.rb
86
+ - lib/inch/badge/config.rb
87
+ - lib/inch/badge/image.rb
88
+ - lib/inch/badge/version.rb
89
+ homepage: ''
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.2.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Rubygem used to generate badges for Inch
113
+ test_files: []