Class: USPSFlags::Helpers

Inherits:
Object
  • Object
show all
Defined in:
lib/usps_flags/helpers.rb

Overview

Container class for helper methods.

Since:

  • 0.1.5

Class Method Summary collapse

Class Method Details

.resize_png(png_file, file: nil, outfile: nil, size:, size_key: nil) ⇒ Object

Resizes and saves a PNG image.

One of the params [file, outfile] is required, and outfile takes precedence.

Parameters:

  • png_file (String)

    Path to the PNG file to resize.

  • file (String) (defaults to: nil)

    Abbreviated key for the output file (e.g. “LTC”, “insignia/FLT”).

  • outfile (String) (defaults to: nil)

    Path to the output file.

  • size (String)

    Actual size to output as.

  • size_key (String) (defaults to: nil)

    Size suffix to attach to the file name.

Raises:

  • (USPSFlags::Errors::PNGConversionError)

Since:

  • 0.1.5



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/usps_flags/helpers.rb', line 30

def resize_png(png_file, file: nil, outfile: nil, size:, size_key: nil)
  raise USPSFlags::Errors::PNGConversionError if outfile.nil? && file.nil?
  raise USPSFlags::Errors::PNGConversionError if outfile.nil? && size_key.nil?
  output_file_name = outfile || "#{USPSFlags.configuration.flags_dir}/PNG/#{file}.#{size_key}.png"
  MiniMagick::Tool::Convert.new do |convert|
    convert << "-background" << "none"
    convert << "-format" << "png"
    convert << "-resize" << "#{size}"
    convert << png_file
    convert << output_file_name
  end
end

.valid_flags(type = :all) ⇒ Array

Valid options for flag generation.

Parameters:

  • type (Symbol) (defaults to: :all)

    Specify subset of flags.

Options Hash (type):

  • :all (Symbol)

    All flags

  • :officer (Symbol)

    Officer flags

  • :insignia (Symbol)

    Insignia-eligible officer flags (no past officers)

  • :squadron (Symbol)

    Squadron-level officer flags

  • :district (Symbol)

    District-level officer flags

  • :national (Symbol)

    National-level officer flags

  • :special (Symbol)

    Special flags

  • :us (Symbol)

    US flag

Returns:

  • (Array)

    Valid options for flag generation (based on the provided type).

Since:

  • 0.1.5



16
17
18
19
# File 'lib/usps_flags/helpers.rb', line 16

def valid_flags(type = :all)
  load_valid_flags
  valid_flags_for(type)
end