Class: Suma::Jsdai::FigureImage
- Inherits:
-
Object
- Object
- Suma::Jsdai::FigureImage
- Defined in:
- lib/suma/jsdai/figure_image.rb
Overview
Represents a JSDAI figure image file
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #dimensions ⇒ Object
-
#initialize(image_file) ⇒ FigureImage
constructor
A new instance of FigureImage.
- #to_base64 ⇒ Object
Constructor Details
#initialize(image_file) ⇒ FigureImage
11 12 13 14 15 16 17 |
# File 'lib/suma/jsdai/figure_image.rb', line 11 def initialize(image_file) @path = image_file @base64_data = nil @width = nil @height = nil @image_type = extract_image_type end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
9 10 11 |
# File 'lib/suma/jsdai/figure_image.rb', line 9 def height @height end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/suma/jsdai/figure_image.rb', line 9 def path @path end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
9 10 11 |
# File 'lib/suma/jsdai/figure_image.rb', line 9 def width @width end |
Instance Method Details
#dimensions ⇒ Object
26 27 28 29 |
# File 'lib/suma/jsdai/figure_image.rb', line 26 def dimensions extract_dimensions unless @width && @height [@width, @height] end |
#to_base64 ⇒ Object
19 20 21 22 23 24 |
# File 'lib/suma/jsdai/figure_image.rb', line 19 def to_base64 @to_base64 ||= begin image_data = File.binread(@path) "data:image/#{@image_type};base64,#{Base64.strict_encode64(image_data)}" end end |