Class: Metanorma::Tools::Figure
- Inherits:
-
Object
- Object
- Metanorma::Tools::Figure
- Defined in:
- lib/metanorma/tools/figure.rb
Constant Summary collapse
- FORMATS =
{ datauri_png: { name: 'PNG', ext: 'png', binary: true }, datauri_jpeg: { name: 'JPEG', ext: 'jpg', binary: true }, datauri_gif: { name: 'GIF', ext: 'gif', binary: true }, datauri_svg: { name: 'SVG', ext: 'svg', binary: false }, datauri_webp: { name: 'WebP', ext: 'webp', binary: true }, svg: { name: 'SVG', ext: 'svg', binary: false } }.freeze
Instance Attribute Summary collapse
-
#autonum ⇒ Object
readonly
Returns the value of attribute autonum.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#file_size ⇒ Object
readonly
Returns the value of attribute file_size.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#original_filename ⇒ Object
readonly
Returns the value of attribute original_filename.
Instance Method Summary collapse
- #format_name ⇒ Object
-
#initialize(autonum, content, format, original_filename = nil) ⇒ Figure
constructor
A new instance of Figure.
- #to_file(output_dir, prefix, document_metadata = nil, retain_original_filenames = false) ⇒ Object
Constructor Details
#initialize(autonum, content, format, original_filename = nil) ⇒ Figure
Returns a new instance of Figure.
21 22 23 24 25 26 27 |
# File 'lib/metanorma/tools/figure.rb', line 21 def initialize(autonum, content, format, original_filename = nil) @autonum = autonum @content = content @format = format @original_filename = original_filename @file_size = calculate_size end |
Instance Attribute Details
#autonum ⇒ Object (readonly)
Returns the value of attribute autonum.
19 20 21 |
# File 'lib/metanorma/tools/figure.rb', line 19 def autonum @autonum end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
19 20 21 |
# File 'lib/metanorma/tools/figure.rb', line 19 def content @content end |
#file_size ⇒ Object (readonly)
Returns the value of attribute file_size.
19 20 21 |
# File 'lib/metanorma/tools/figure.rb', line 19 def file_size @file_size end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
19 20 21 |
# File 'lib/metanorma/tools/figure.rb', line 19 def format @format end |
#original_filename ⇒ Object (readonly)
Returns the value of attribute original_filename.
19 20 21 |
# File 'lib/metanorma/tools/figure.rb', line 19 def original_filename @original_filename end |
Instance Method Details
#format_name ⇒ Object
40 41 42 |
# File 'lib/metanorma/tools/figure.rb', line 40 def format_name FORMATS.dig(@format, :name) || @format.to_s.upcase end |
#to_file(output_dir, prefix, document_metadata = nil, retain_original_filenames = false) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/metanorma/tools/figure.rb', line 29 def to_file(output_dir, prefix, = nil, retain_original_filenames = false) FileUtils.mkdir_p(output_dir) filename = generate_filename(prefix, , retain_original_filenames) filepath = File.join(output_dir, filename) write_content(filepath) puts " Saved: #{filename}" filepath end |