Method: Blufin::Image.calc_file_name
- Defined in:
- lib/core/image.rb
.calc_file_name(prefix, ext, side, length, ratio) ⇒ Object
Standardizes the way output files are named.
133 134 135 136 137 138 139 140 |
# File 'lib/core/image.rb', line 133 def self.calc_file_name(prefix, ext, side, length, ratio) raise RuntimeError, "Expected integer, instead got: #{length}" unless length.to_s =~ /^\d+$/ raise RuntimeError, "Expected one of: #{VALID_SIDES.inspect}, instead got: #{side}" unless VALID_SIDES.include?(side) raise RuntimeError, "Unexpected ratio #{Blufin::Terminal::format_highlight(ratio)}, expected something like: 16:9" unless ratio =~ /\d{1,2}:\d{1,2}/ x = side == 'width' ? length : calc_width_from_ratio(ratio, length) y = side == 'width' ? calc_height_from_ratio(ratio, length) : length "#{prefix}-#{x}x#{y}.#{ext.downcase}" end |