svgshield 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
  SHA1:
3
- metadata.gz: 8f15084c4017e592e7475989d0eac4cf6c7411f7
4
- data.tar.gz: 60bb1f8dc3184cf1eb669b6a811ed00b3768c547
3
+ metadata.gz: 98c71f4e4668d935007fd16f61e3fa01bd22e5f8
4
+ data.tar.gz: 564d22d63da5aa2e1250139814b04ff48b78bc3a
5
5
  SHA512:
6
- metadata.gz: 94a4786f17d7100380fdbf9946c8e4a773a419ae2613eac8890dae35708595cc22c8b09cbe28e59f8e7e23dd5292d9022b50901b08bfeded74c141d4bcf7ff96
7
- data.tar.gz: 43b864f38614f6366cd8f38a744a307f3256344bb22441a761bc16196ba22760f8d2588ffc38284cfc549825116a7f3cfa565eb56ff52374c30cd846fc2bbba1
6
+ metadata.gz: 5fdd57a767b1a78b7ad742313a9b44ddd5ffdd58c5ac3c3f33ba308143e86ba16a0567e185a142ffb0580676baf83e45a58ba941825f37616dd8046e08009c72
7
+ data.tar.gz: af68cde0e251c61e92fd2c49c83a823a4d4e5abe2cb0cb6ef38cb814da24df35e5fdfe2972999936472e94de28bce2e3e2f08eb314f3ecbb477cedacf5957921
data/README.md CHANGED
@@ -18,7 +18,7 @@ And then execute:
18
18
 
19
19
  ## Usage
20
20
 
21
- To generate an image object:
21
+ To generate an image XML string:
22
22
 
23
23
  ```ruby
24
24
  redimage1 = Svgshield.new('Subject', 'Status', 'red').to_s # color words
@@ -1,3 +1,3 @@
1
1
  class Svgshield
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/svgshield.rb CHANGED
@@ -8,16 +8,26 @@ class Svgshield
8
8
  def initialize(subject, status, color = '#aaa')
9
9
  color = Color::CSS[color] if color[0] == '#'
10
10
 
11
- @shield = Rasem::SVGImage.new(width: 90, height: 20) do
12
- linearGradient('a', x2: 0, y2: '100%') do
11
+ # subject_width = 37
12
+ # status_width = 53
13
+ full_width = 86
14
+ full_height = 20
15
+
16
+ @shield = Rasem::SVGImage.new(width: full_width, height: full_height) do
17
+ linearGradient('b', x2: 0, y2: '100%') do
13
18
  stop 0, '#bbb', '.1'
14
19
  stop 1, nil, '.1'
15
20
  end
16
21
 
17
- rect nil, nil, '90', '20', '3', fill: '#555', stroke_width: 0
18
- rect '37', nil, '53', '20', '3', fill: color, stroke_width: 0
19
- path fill: color, d: 'M37 0h4v20h-4z'
20
- rect nil, nil, '90', '20', '3', fill: 'url(#a)', stroke_width: 0
22
+ clipPath(id: 'a') do
23
+ rect nil, nil, full_width, full_height, rx: 3, stroke_width: 0, fill: '#fff'
24
+ end
25
+
26
+ group 'clip-path' => 'url(#a)' do
27
+ path fill: '#555', d: "M0 0h37v#{full_height}H0z"
28
+ path fill: color, d: "M37 0h49v#{full_height}H37z"
29
+ path fill: 'url(#b)' d: "M0 0h#{full_width}v#{full_height}H0z"
30
+ end
21
31
 
22
32
  group(
23
33
  fill: '#fff',
@@ -25,10 +35,10 @@ class Svgshield
25
35
  'font-family' => 'DejaVu Sans,Verdana,Geneva,sans-serif',
26
36
  'font-size' => 11
27
37
  ) do
28
- text(19.5, 15, fill: '#010101', 'fill-opacity' => '.3') { raw subject }
29
- text(19.5, 14, fill: '#fff') { raw subject }
30
- text(62.5, 15, fill: '#010101', 'fill-opacity' => '.3') { raw status }
31
- text(62.5, 14, fill: '#fff') { raw status }
38
+ text(18.5, 15, fill: '#010101', 'fill-opacity' => '.3') { raw subject }
39
+ text(18.5, 14, fill: '#fff') { raw subject }
40
+ text(60.5, 15, fill: '#010101', 'fill-opacity' => '.3') { raw status }
41
+ text(60.5, 14, fill: '#fff') { raw status }
32
42
  end
33
43
  end
34
44
  end
@@ -36,4 +46,23 @@ class Svgshield
36
46
  def to_s
37
47
  shield.to_s
38
48
  end
49
+
50
+ private
51
+
52
+ def string_width(string)
53
+ # Output is (theoretically, anyway) in pixels
54
+
55
+ string.chars.inject(0) { |sum, char| sum + char_width(char) }.round 0
56
+ end
57
+
58
+ def char_width(char)
59
+ {
60
+ 'i' => 8.0,
61
+ 'j' => 9.0,
62
+ 'l' => 6.0,
63
+ 'm' => 11.0,
64
+ 'w' => 11.0,
65
+ '1' => 8.5
66
+ }[char] || 9.0
67
+ end
39
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svgshield
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
  - Evertrue, Inc
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-11 00:00:00.000000000 Z
11
+ date: 2017-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rasem