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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Config

Configuration constructor

Parameters:

  • flag_dir (String)

    The path to the flags directory.

  • use_larger_tridents (Boolean)

    Whether to use the larger trident configuration.

  • log_fail_quietly (Boolean)

    Whether to print an error message if the log file is inaccessible.

  • reset (Boolean)

    Whether to clear out the specified flags_dir.

Yields:

  • (_self)

Yield Parameters:

Since:

  • 0.1.5



21
22
23
24
25
26
# File 'lib/usps_flags/config.rb', line 21

def initialize
  load_init_variables
  yield self if block_given?
  set_flags_dir(reset: @reset)
  set_class_variables
end

Instance Attribute Details

#flags_dirObject

Since:

  • 0.1.5



28
29
30
# File 'lib/usps_flags/config.rb', line 28

def flags_dir
  @flags_dir
end

#log_fail_quietlyObject

Since:

  • 0.1.5



31
32
33
# File 'lib/usps_flags/config.rb', line 31

def log_fail_quietly
  @log_fail_quietly
end

#resetObject

Since:

  • 0.1.5



29
30
31
# File 'lib/usps_flags/config.rb', line 29

def reset
  @reset
end

#use_larger_tridentsObject

Since:

  • 0.1.5



30
31
32
# File 'lib/usps_flags/config.rb', line 30

def use_larger_tridents
  @use_larger_tridents
end

Class Method Details

.flags_dirString

Accessor for the directory for storing generated flags.

Returns:

  • (String)

    The current path to the flags directory.

Since:

  • 0.1.5



82
83
84
# File 'lib/usps_flags/config.rb', line 82

def self.flags_dir
  @@flags_dir
end

.log_fail_quietlyBoolean

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

Returns:

  • (Boolean)

    Returns the current setting.

Since:

  • 0.1.5



111
112
113
# File 'lib/usps_flags/config.rb', line 111

def self.log_fail_quietly
  @@log_fail_quietly
end

.log_pathString

Alias for the directory to store generated log files.

Returns:

  • (String)

    The current path to the logs directory.

Since:

  • 0.1.5



89
90
91
92
93
94
95
96
97
# File 'lib/usps_flags/config.rb', line 89

def self.log_path
  log_path = if defined?(::Rails)
    "#{::Rails.root}/log"
  else
    "#{@@flags_dir}/log"
  end
  ::FileUtils.mkdir_p(log_path)
  log_path
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



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/usps_flags/config.rb', line 38

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_tridentsBoolean

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

Returns:

  • (Boolean)

    Returns the current setting.

Since:

  • 0.1.5



102
103
104
105
106
# File 'lib/usps_flags/config.rb', line 102

def self.use_larger_tridents
  # Smaller: 1/2 in width on 24in x 16in field
  # Larger:  5/8 in width on 24in x 16in field
  @@use_larger_tridents
end