Class: Rspreadsheet::Image

Inherits:
XMLTiedItem
  • Object
show all
Defined in:
lib/rspreadsheet/image.rb

Overview

Represents an image included in the spreadsheet. The Image can NOT exist "detached" from an spreadsheet

XMLTiedArray_WithRepeatableItems related methods collapse

XMLTiedArray_WithRepeatableItems related methods collapse

Constructor Details

#initialize(worksheet, index) ⇒ Image

Returns a new instance of Image.


63
64
65
66
# File 'lib/rspreadsheet/image.rb', line 63

def initialize(worksheet,index)
  super(worksheet,index)
  @original_filename = nil
end

Instance Attribute Details

#mimeObject (readonly)

Returns the value of attribute mime.


61
62
63
# File 'lib/rspreadsheet/image.rb', line 61

def mime
  @mime
end

Instance Method Details

#copy_to(ax, ay, worksheet) ⇒ Object


86
87
88
89
90
# File 'lib/rspreadsheet/image.rb', line 86

def copy_to(ax,ay,worksheet)
  img = worksheet.insert_image_to(ax,ay,@original_filename)
  img.height = height
  img.width  = width
end

#heightObject


101
# File 'lib/rspreadsheet/image.rb', line 101

def height; Tools.get_ns_attribute_value(xmlnode,'svg','height') end

#height=(value) ⇒ Object


96
# File 'lib/rspreadsheet/image.rb', line 96

def height=(value); Tools.set_ns_attribute(xmlnode,'svg','height',value) end

#initialize_from_file(filename, mime) ⇒ Object


68
69
70
71
72
73
74
# File 'lib/rspreadsheet/image.rb', line 68

def initialize_from_file(filename,mime)
  # ověřit, zda soubor na disku existuje TODO: tady by to chtělo zobecnit na IO
  raise 'File does not exist or it is not accessible' unless File.exist?(filename)
  @original_filename = filename
  @mime = mime
  self
end

#internal_filenameObject


103
# File 'lib/rspreadsheet/image.rb', line 103

def internal_filename; Tools.get_ns_attribute_value(xml_image_subnode,'xlink','href')  end

#internal_filename=(value) ⇒ Object


104
105
106
# File 'lib/rspreadsheet/image.rb', line 104

def internal_filename=(value)
  Tools.set_ns_attribute(xml_image_subnode,'xlink','href', value ) 
end

#move_to(ax, ay) ⇒ Object


79
80
81
82
# File 'lib/rspreadsheet/image.rb', line 79

def move_to(ax,ay)
  self.x = ax
  self.y = ay
end

#nameObject


102
# File 'lib/rspreadsheet/image.rb', line 102

def name;   Tools.get_ns_attribute_value(xmlnode, 'draw', 'name', nil) end

#name=(value) ⇒ Object


97
# File 'lib/rspreadsheet/image.rb', line 97

def name=(value);   Tools.set_ns_attribute(xmlnode,'draw','name', value) end

#original_filenameObject


84
# File 'lib/rspreadsheet/image.rb', line 84

def original_filename; @original_filename end

#widthObject


100
# File 'lib/rspreadsheet/image.rb', line 100

def width;  Tools.get_ns_attribute_value(xmlnode,'svg','width') end

#width=(value) ⇒ Object


95
# File 'lib/rspreadsheet/image.rb', line 95

def width=(value);  Tools.set_ns_attribute(xmlnode,'svg','width', value) end

#xObject


98
# File 'lib/rspreadsheet/image.rb', line 98

def x;      Tools.get_ns_attribute_value(xmlnode,'svg','x') end

#x=(value) ⇒ Object

TODO: put some sanity check for values into these


93
# File 'lib/rspreadsheet/image.rb', line 93

def x=(value);      Tools.set_ns_attribute(xmlnode,'svg','x',     value) end

#xml_image_subnodeObject


75
76
77
# File 'lib/rspreadsheet/image.rb', line 75

def xml_image_subnode
  xmlnode.find('./draw:image').first
end

#yObject


99
# File 'lib/rspreadsheet/image.rb', line 99

def y;      Tools.get_ns_attribute_value(xmlnode,'svg','y') end

#y=(value) ⇒ Object


94
# File 'lib/rspreadsheet/image.rb', line 94

def y=(value);      Tools.set_ns_attribute(xmlnode,'svg','y',     value) end