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



36
37
38
39
40
41
42
# File 'lib/usps_flags/helpers.rb', line 36

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"
  resize_convert(size, png_file, output_file_name)
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



20
21
22
23
24
25
# File 'lib/usps_flags/helpers.rb', line 20

def valid_flags(type = :all)
  USPSFlags::Helpers::ValidFlags.load_valid_flags
  USPSFlags::Helpers::ValidFlags.load_special_flags
  USPSFlags::Helpers::ValidFlags.load_valid_flag_groups
  USPSFlags::Helpers::ValidFlags.valid_flags_for(type)
end