Class: Sablon::Content::Image
- Inherits:
-
Struct
- Object
- Struct
- Sablon::Content::Image
- Defined in:
- lib/sablon/content.rb
Overview
Handles reading image data and inserting it into the document
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#local_rid ⇒ Object
Returns the value of attribute local_rid.
-
#name ⇒ Object
Returns the value of attribute name.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#rid_by_file ⇒ Object
readonly
Returns the value of attribute rid_by_file.
Class Method Summary collapse
Instance Method Summary collapse
- #append_to(paragraph, display_node, env) ⇒ Object
- #height ⇒ Object
-
#initialize(source, attributes = {}) ⇒ Image
constructor
A new instance of Image.
- #inspect ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(source, attributes = {}) ⇒ Image
Returns a new instance of Image.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/sablon/content.rb', line 187 def initialize(source, attributes = {}) attributes = Hash[attributes.map { |k, v| [k.to_s, v] }] # If the source object is readable, use it as such otherwise open # and read the content if source.respond_to?(:read) name, img_data = process_readable(source, attributes) else name = File.basename(source) img_data = IO.binread(source) end # super name, img_data @attributes = attributes @properties = @attributes.fetch("properties", {}) # rId's are separate for each XML file but I want to be able # to reuse the actual image file itself. @rid_by_file = {} end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data
176 177 178 |
# File 'lib/sablon/content.rb', line 176 def data @data end |
#local_rid ⇒ Object
Returns the value of attribute local_rid.
178 179 180 |
# File 'lib/sablon/content.rb', line 178 def local_rid @local_rid end |
#name ⇒ Object
Returns the value of attribute name
176 177 178 |
# File 'lib/sablon/content.rb', line 176 def name @name end |
#properties ⇒ Object
Returns the value of attribute properties
176 177 178 |
# File 'lib/sablon/content.rb', line 176 def properties @properties end |
#rid_by_file ⇒ Object (readonly)
Returns the value of attribute rid_by_file.
177 178 179 |
# File 'lib/sablon/content.rb', line 177 def rid_by_file @rid_by_file end |
Class Method Details
.id ⇒ Object
180 |
# File 'lib/sablon/content.rb', line 180 def self.id; :image end |
.wraps?(value) ⇒ Boolean
181 |
# File 'lib/sablon/content.rb', line 181 def self.wraps?(value) false end |
Instance Method Details
#append_to(paragraph, display_node, env) ⇒ Object
217 |
# File 'lib/sablon/content.rb', line 217 def append_to(paragraph, display_node, env) end |
#height ⇒ Object
212 213 214 215 |
# File 'lib/sablon/content.rb', line 212 def height return unless (height_str = @properties[:height]) convert_to_emu(height_str) end |
#inspect ⇒ Object
183 184 185 |
# File 'lib/sablon/content.rb', line 183 def inspect "#<Image #{name}:#{@rid_by_file}>" end |
#width ⇒ Object
207 208 209 210 |
# File 'lib/sablon/content.rb', line 207 def width return unless (width_str = @properties[:width]) convert_to_emu(width_str) end |