svg_profiler 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ ## SVG Profiler
2
+
3
+ Profiles a Scalable Vector Graphics xml string.
4
+
5
+ ## Usage
6
+
7
+ ```
8
+ require "svg_profiler"
9
+
10
+ profile = SVGProfiler.new(File.read("file.svg"))
11
+
12
+ profile.dimensions
13
+ #=> [900, 600]
14
+
15
+ profile.width
16
+ #=> 900
17
+
18
+ profile.height
19
+ #=> 600
20
+
21
+ profile.aspect
22
+ #=> 1.5
23
+ ```
24
+
25
+ ## Contribution
26
+
27
+ If there's a metric you'd like to see implemented, please send a pull request or open an issue.
@@ -0,0 +1,40 @@
1
+ class SVGProfiler
2
+
3
+ attr_reader :xml
4
+
5
+ def initialize(xml_string)
6
+ @xml = Nokogiri::XML(xml_string)
7
+ end
8
+
9
+ def dimensions
10
+ svg = xml.css("svg")
11
+
12
+ width, height = %w(width height).map { |s| attribute(svg, s) }
13
+ view_box = attribute(svg, "viewBox")
14
+
15
+ if view_box
16
+ _, _, v_width, v_height = view_box.split(" ")
17
+ end
18
+
19
+ [width || v_width, height || v_height].map(&:to_i)
20
+ end
21
+
22
+ def width
23
+ dimensions.first
24
+ end
25
+
26
+ def height
27
+ dimensions.last
28
+ end
29
+
30
+ def aspect
31
+ width.to_f / height
32
+ end
33
+
34
+ private
35
+ def attribute(node, attribute)
36
+ a = node.attr(attribute)
37
+ a.value if a
38
+ end
39
+
40
+ end
@@ -0,0 +1,3 @@
1
+ require "nokogiri"
2
+
3
+ require "svg_profiler/base"
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: svg_profiler
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Chris Patuzzo
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-03-09 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: nokogiri
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ description: Profiles a Scalable Vector Graphics xml string.
50
+ email: chris@patuzzo.co.uk
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - README.md
59
+ - lib/svg_profiler/base.rb
60
+ - lib/svg_profiler.rb
61
+ has_rdoc: true
62
+ homepage: https://github.com/cpatuzzo/svg_profiler
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options: []
67
+
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project:
91
+ rubygems_version: 1.6.2
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: SVG Profiler
95
+ test_files: []
96
+