Class: ReportBuilder::ImageBlob

Inherits:
Image
  • Object
show all
Defined in:
lib/reportbuilder/image.rb

Instance Attribute Summary collapse

Attributes inherited from Image

#alt, #chars, #filename, #font_cols, #font_rows, #height, #id, #name, #svg_raster, #type, #url, #width

Instance Method Summary collapse

Methods inherited from Image

#generate_raster_from_svg, #generate_tag_html, #image_magick, #report_building_html, #report_building_pdf, #report_building_rtf, #report_building_text

Constructor Details

#initialize(blob, options = Hash.new) ⇒ ImageBlob

Returns a new instance of ImageBlob.



168
169
170
171
172
173
174
175
176
177
178
# File 'lib/reportbuilder/image.rb', line 168

def initialize(blob, options=Hash.new)
  super(options)
  @blob=blob      
  if !@type
    if blob[0,40]=~/<svg/
      @type='svg'
    else
      @type='jpg'
    end
  end
end

Instance Attribute Details

#blobObject

Returns the value of attribute blob.



167
168
169
# File 'lib/reportbuilder/image.rb', line 167

def blob
  @blob
end

Instance Method Details

#_image_magickObject



179
180
181
182
183
184
185
186
187
# File 'lib/reportbuilder/image.rb', line 179

def _image_magick
    that=self
    img=Magick::Image.from_blob(@blob) { 
      if that.type=='svg'
        self.format='SVG'
      end
    }
    img.first
end

#create_file(directory) ⇒ Object



188
189
190
191
192
193
194
195
196
# File 'lib/reportbuilder/image.rb', line 188

def create_file(directory)
  FileUtils.mkdir_p directory+"/images"
  @filename=directory+"/images/"+@id+"."+@type
  @url="images/"+@id+"."+@type
  File.open(@filename,"w") do |fp|
    fp.write @blob
  end
  @filename
end