Class: USPSFlags::Config

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

Overview

Container class for configuration values.

Since:

  • 0.1.5

Class Method Summary collapse

Class Method Details

.flags_dir(init = nil, reset: false) ⇒ String

Accessor for the directory for storing generated flags.

Examples:

Update flag storage directory

# Rails.root => "/path/to"
USPSFlags::Config.flags_dir "#{Rails.root}/app/assets/images/flags" #=> "/path/to/app/assets/images/flags"

Update flag storage directory that already has some files in it

# Rails.root => "/path/to"
USPSFlags::Config.flags_dir "#{Rails.root}/app/assets/images/flags", reset: true #=> "/path/to/app/assets/images/flags"

Parameters:

  • init (String) (defaults to: nil)

    If set, updates the path to the directory for storing generated flags.

  • reset (Boolean) (defaults to: false)

    Delete all files in the specified directory if found.

Returns:

  • (String)

    Returns the current (or updated) path to the flags directory.

Since:

  • 0.1.5



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/usps_flags/config.rb', line 26

def self.flags_dir(init = nil, reset: false)
  unless init.nil?
    @@flags_dir = init
    ::FileUtils.rm_rf(USPSFlags::Config.flags_dir) if reset
    [
      "#{USPSFlags::Config.flags_dir}/SVG/insignia",
      "#{USPSFlags::Config.flags_dir}/PNG/insignia",
      "#{USPSFlags::Config.flags_dir}/ZIP"
    ].each do |dir|
      ::FileUtils.mkdir_p(dir)
    end
    ::FileUtils.mkdir_p(USPSFlags::Config.log_path) unless defined?(Rails)
  end
  @@flags_dir
end

.log_fail_quietly(bool = nil) ⇒ Boolean

Accessor for the boolean of whether to print an error message if the log file is inaccessible.

Parameters:

  • bool (Boolean) (defaults to: nil)

    If set to a Boolean, specify whether to print the error message.

Returns:

  • (Boolean)

    Returns the current (or updated) setting.

Since:

  • 0.1.5



75
76
77
78
# File 'lib/usps_flags/config.rb', line 75

def self.log_fail_quietly(bool = nil)
  @@log_fail_quietly = bool if [true, false].include?(bool)
  @@log_fail_quietly
end

.log_pathObject

Alias for the directory to store generated log files.

Examples:

Rails

# Rails.root => "/path/to"
USPSFlags::Config.logs_dir #=> "/path/to/log"

Non-Rails

USPSFlags::Config.logs_dir #=> "/app/root/log"

Since:

  • 0.1.5



50
51
52
53
54
55
56
57
58
# File 'lib/usps_flags/config.rb', line 50

def self.log_path
  if defined?(Rails)
    "#{Rails.root}/log"
  else
    log_dir = "#{self.flags_dir}/log"
    ::FileUtils.mkdir_p(log_dir)
    log_dir
  end
end

.tridentHash

Base configuration values for trident insignia.

All other values are derived from these, or directly from the constant sizes.

Returns:

  • (Hash)

    Returns the configuration values for tridents.

Since:

  • 0.1.5



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/usps_flags/config.rb', line 85

def self.trident
  point_height = USPSFlags::Config::BASE_FLY/48*17/8
  bar_width = USPSFlags::Config::BASE_FLY/48
  bar_width = bar_width*5/4 if self.use_larger_tridents
  {
    height: {
      s:   USPSFlags::Config::BASE_HOIST/2,
      d:   USPSFlags::Config::BASE_HOIST*5/8,
      stf: USPSFlags::Config::BASE_HOIST*3/4,
      n:   USPSFlags::Config::BASE_HOIST*3/4
    },

    center_point: BASE_FLY/2,

    width: USPSFlags::Config::BASE_FLY*5/32,

    bar_width: bar_width,

    point_height: point_height,

    main_point_barb: USPSFlags::Config::BASE_HOIST/240,

    crossbar_from_top: USPSFlags::Config::BASE_HOIST/4,

    side_spike_height: USPSFlags::Config::BASE_HOIST/4-point_height-bar_width,

    hash_width: USPSFlags::Config::BASE_FLY*3/32,

    delta_height: USPSFlags::Config::BASE_FLY*2/15,
    delta_gap_height: self.use_larger_tridents ? USPSFlags::Config::BASE_FLY*14/256 : USPSFlags::Config::BASE_FLY*17/256,
    delta_gap_width: self.use_larger_tridents ? bar_width*5/4 : bar_width*7/4,
    delta_width: USPSFlags::Config::BASE_FLY*43/768,
    delta_from_bottom: USPSFlags::Config::BASE_HOIST*11/64,
    delta_gap_scale: 0.40,
    delta_gap_x: USPSFlags::Config::BASE_HOIST*144/128,
    delta_gap_y: USPSFlags::Config::BASE_HOIST*221/256,

    circle_height_adj: USPSFlags::Config::BASE_FLY/800
  }
end

.use_larger_tridents(bool = nil) ⇒ Boolean

Accessor for the boolean of whether to use the larger or smaller trident width.

Parameters:

  • bool (Boolean) (defaults to: nil)

    If set to a Boolean, specify whether to use the larger trident width.

Returns:

  • (Boolean)

    Returns the current (or updated) setting.

Since:

  • 0.1.5



64
65
66
67
68
69
# File 'lib/usps_flags/config.rb', line 64

def self.use_larger_tridents(bool = nil)
  # Smaller: 1/2 in width on 24in x 16in field
  # Larger:  5/8 in width on 24in x 16in field
  @@use_larger_tridents = bool unless bool.nil? || !([true, false].include?(bool))
  @@use_larger_tridents 
end