Class: Vectory::Vector
Instance Attribute Summary collapse
-
#initial_path ⇒ Object
readonly
Returns the value of attribute initial_path.
Attributes inherited from Image
Class Method Summary collapse
- .default_extension ⇒ Object
- .from_datauri(uri) ⇒ Object
- .from_path(path) ⇒ Object
- .mimetype ⇒ Object
Instance Method Summary collapse
- #file_size ⇒ Object
- #height ⇒ Object
-
#initialize(content = nil, initial_path = nil) ⇒ Vector
constructor
A new instance of Vector.
- #mime ⇒ Object
- #path ⇒ Object
- #size ⇒ Object
- #to_uri ⇒ Object
- #width ⇒ Object
- #write(path = nil) ⇒ Object
Methods inherited from Image
Constructor Details
#initialize(content = nil, initial_path = nil) ⇒ Vector
Returns a new instance of Vector.
28 29 30 31 32 |
# File 'lib/vectory/vector.rb', line 28 def initialize(content = nil, initial_path = nil) super(content) @initial_path = initial_path end |
Instance Attribute Details
#initial_path ⇒ Object (readonly)
Returns the value of attribute initial_path.
26 27 28 |
# File 'lib/vectory/vector.rb', line 26 def initial_path @initial_path end |
Class Method Details
.default_extension ⇒ Object
16 17 18 19 |
# File 'lib/vectory/vector.rb', line 16 def self.default_extension raise Vectory::NotImplementedError, "#default_extension should be implemented in a subclass." end |
.from_datauri(uri) ⇒ Object
12 13 14 |
# File 'lib/vectory/vector.rb', line 12 def self.from_datauri(uri) Datauri.new(uri).to_vector end |
.from_path(path) ⇒ Object
7 8 9 10 |
# File 'lib/vectory/vector.rb', line 7 def self.from_path(path) content = File.read(path, mode: "rb") new(content, path) end |
.mimetype ⇒ Object
21 22 23 24 |
# File 'lib/vectory/vector.rb', line 21 def self.mimetype raise Vectory::NotImplementedError, "#mimetype should be implemented in a subclass." end |
Instance Method Details
#file_size ⇒ Object
42 43 44 45 46 |
# File 'lib/vectory/vector.rb', line 42 def file_size raise(NotWrittenToDiskError) unless @path File.size(@path) end |
#height ⇒ Object
48 49 50 |
# File 'lib/vectory/vector.rb', line 48 def height InkscapeWrapper.instance.height(content, self.class.default_extension) end |
#mime ⇒ Object
34 35 36 |
# File 'lib/vectory/vector.rb', line 34 def mime self.class.mimetype end |
#path ⇒ Object
68 69 70 |
# File 'lib/vectory/vector.rb', line 68 def path @path || raise(NotWrittenToDiskError) end |
#size ⇒ Object
38 39 40 |
# File 'lib/vectory/vector.rb', line 38 def size content.bytesize end |
#to_uri ⇒ Object
56 57 58 |
# File 'lib/vectory/vector.rb', line 56 def to_uri Datauri.from_vector(self) end |
#width ⇒ Object
52 53 54 |
# File 'lib/vectory/vector.rb', line 52 def width InkscapeWrapper.instance.width(content, self.class.default_extension) end |
#write(path = nil) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/vectory/vector.rb', line 60 def write(path = nil) target_path = path || @path || tmp_path File.binwrite(target_path, content) @path = File.(target_path) self end |