Class: Vectory::Vector

Inherits:
Image
  • Object
show all
Defined in:
lib/vectory/vector.rb

Direct Known Subclasses

Emf, Eps, Pdf, Ps, Svg

Instance Attribute Summary collapse

Attributes inherited from Image

#content

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Image

from_content

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_pathObject (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_extensionObject



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

.mimetypeObject



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_sizeObject



42
43
44
45
46
# File 'lib/vectory/vector.rb', line 42

def file_size
  raise(NotWrittenToDiskError) unless @path

  File.size(@path)
end

#heightObject



48
49
50
# File 'lib/vectory/vector.rb', line 48

def height
  InkscapeWrapper.instance.height(content, self.class.default_extension)
end

#mimeObject



34
35
36
# File 'lib/vectory/vector.rb', line 34

def mime
  self.class.mimetype
end

#pathObject



68
69
70
# File 'lib/vectory/vector.rb', line 68

def path
  @path || raise(NotWrittenToDiskError)
end

#sizeObject



38
39
40
# File 'lib/vectory/vector.rb', line 38

def size
  content.bytesize
end

#to_uriObject



56
57
58
# File 'lib/vectory/vector.rb', line 56

def to_uri
  Datauri.from_vector(self)
end

#widthObject



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.expand_path(target_path)

  self
end