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
- #convert_with_inkscape(inkscape_options, target_class) ⇒ Object
- #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.
29 30 31 32 33 |
# File 'lib/vectory/vector.rb', line 29 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.
27 28 29 |
# File 'lib/vectory/vector.rb', line 27 def initial_path @initial_path end |
Class Method Details
.default_extension ⇒ Object
17 18 19 20 |
# File 'lib/vectory/vector.rb', line 17 def self.default_extension raise Vectory::NotImplementedError, "#default_extension should be implemented in a subclass." end |
.from_datauri(uri) ⇒ Object
13 14 15 |
# File 'lib/vectory/vector.rb', line 13 def self.from_datauri(uri) Datauri.new(uri).to_vector end |
.from_path(path) ⇒ Object
8 9 10 11 |
# File 'lib/vectory/vector.rb', line 8 def self.from_path(path) content = File.read(path, mode: "rb") new(content, path) end |
.mimetype ⇒ Object
22 23 24 25 |
# File 'lib/vectory/vector.rb', line 22 def self.mimetype raise Vectory::NotImplementedError, "#mimetype should be implemented in a subclass." end |
Instance Method Details
#convert_with_inkscape(inkscape_options, target_class) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/vectory/vector.rb', line 61 def convert_with_inkscape(, target_class) with_file(self.class.default_extension) do |input_path| output_extension = target_class.default_extension output_path = InkscapeConverter.instance.convert(input_path, output_extension, ) target_class.from_path(output_path) end end |
#file_size ⇒ Object
43 44 45 46 47 |
# File 'lib/vectory/vector.rb', line 43 def file_size raise(NotWrittenToDiskError) unless @path File.size(@path) end |
#height ⇒ Object
49 50 51 |
# File 'lib/vectory/vector.rb', line 49 def height InkscapeConverter.instance.height(content, self.class.default_extension) end |
#mime ⇒ Object
35 36 37 |
# File 'lib/vectory/vector.rb', line 35 def mime self.class.mimetype end |
#path ⇒ Object
80 81 82 |
# File 'lib/vectory/vector.rb', line 80 def path @path || raise(NotWrittenToDiskError) end |
#size ⇒ Object
39 40 41 |
# File 'lib/vectory/vector.rb', line 39 def size content.bytesize end |
#to_uri ⇒ Object
57 58 59 |
# File 'lib/vectory/vector.rb', line 57 def to_uri Datauri.from_vector(self) end |
#width ⇒ Object
53 54 55 |
# File 'lib/vectory/vector.rb', line 53 def width InkscapeConverter.instance.width(content, self.class.default_extension) end |
#write(path = nil) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/vectory/vector.rb', line 72 def write(path = nil) target_path = path || @path || tmp_path File.binwrite(target_path, content) @path = File.(target_path) self end |