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
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.
25 26 27 28 29 |
# File 'lib/vectory/vector.rb', line 25 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.
23 24 25 |
# File 'lib/vectory/vector.rb', line 23 def initial_path @initial_path end |
Class Method Details
.default_extension ⇒ Object
13 14 15 16 |
# File 'lib/vectory/vector.rb', line 13 def self.default_extension raise Vectory::NotImplementedError, "#default_extension should be implemented in a subclass." 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
18 19 20 21 |
# File 'lib/vectory/vector.rb', line 18 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
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/vectory/vector.rb', line 57 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
39 40 41 42 43 |
# File 'lib/vectory/vector.rb', line 39 def file_size raise(NotWrittenToDiskError) unless @path File.size(@path) end |
#height ⇒ Object
45 46 47 |
# File 'lib/vectory/vector.rb', line 45 def height InkscapeConverter.instance.height(content, self.class.default_extension) end |
#mime ⇒ Object
31 32 33 |
# File 'lib/vectory/vector.rb', line 31 def mime self.class.mimetype end |
#path ⇒ Object
76 77 78 |
# File 'lib/vectory/vector.rb', line 76 def path @path || raise(NotWrittenToDiskError) end |
#size ⇒ Object
35 36 37 |
# File 'lib/vectory/vector.rb', line 35 def size content.bytesize end |
#to_uri ⇒ Object
53 54 55 |
# File 'lib/vectory/vector.rb', line 53 def to_uri Datauri.from_vector(self) end |
#width ⇒ Object
49 50 51 |
# File 'lib/vectory/vector.rb', line 49 def width InkscapeConverter.instance.width(content, self.class.default_extension) end |
#write(path = nil) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/vectory/vector.rb', line 68 def write(path = nil) target_path = path || @path || tmp_path File.binwrite(target_path, content) @path = File.(target_path) self end |