usps_flags 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +22 -11
- data/.travis.yml +1 -1
- data/Gemfile.lock +5 -2
- data/README.md +6 -0
- data/lib/usps_flags.rb +35 -44
- data/lib/usps_flags/config.rb +89 -87
- data/lib/usps_flags/core.rb +44 -42
- data/lib/usps_flags/core/ensign.rb +53 -49
- data/lib/usps_flags/core/field.rb +96 -92
- data/lib/usps_flags/core/footer.rb +9 -5
- data/lib/usps_flags/core/headers.rb +58 -48
- data/lib/usps_flags/core/icons.rb +11 -7
- data/lib/usps_flags/core/icons/anchor.rb +62 -56
- data/lib/usps_flags/core/icons/binoculars.rb +21 -15
- data/lib/usps_flags/core/icons/lighthouse.rb +28 -22
- data/lib/usps_flags/core/icons/star.rb +21 -15
- data/lib/usps_flags/core/icons/trident.rb +136 -127
- data/lib/usps_flags/core/icons/trident_parts/hashes.rb +62 -55
- data/lib/usps_flags/core/icons/trumpet.rb +34 -28
- data/lib/usps_flags/core/pennant.rb +50 -46
- data/lib/usps_flags/core/trident_spec.rb +135 -131
- data/lib/usps_flags/core/trident_specs.rb +11 -7
- data/lib/usps_flags/core/trident_specs/base.rb +36 -26
- data/lib/usps_flags/core/trident_specs/circle.rb +36 -30
- data/lib/usps_flags/core/trident_specs/delta.rb +41 -30
- data/lib/usps_flags/core/trident_specs/header.rb +56 -50
- data/lib/usps_flags/core/trident_specs/horizontal.rb +80 -0
- data/lib/usps_flags/core/trident_specs/long.rb +41 -25
- data/lib/usps_flags/core/trident_specs/overlay.rb +40 -0
- data/lib/usps_flags/core/trident_specs/short.rb +30 -156
- data/lib/usps_flags/core/trident_specs/vertical.rb +108 -0
- data/lib/usps_flags/core/tridents.rb +54 -50
- data/lib/usps_flags/core/us.rb +40 -44
- data/lib/usps_flags/core/wheel.rb +7 -3
- data/lib/usps_flags/errors.rb +25 -23
- data/lib/usps_flags/generate.rb +111 -107
- data/lib/usps_flags/generate/flag.rb +160 -157
- data/lib/usps_flags/generate/generator_methods.rb +139 -0
- data/lib/usps_flags/generate/helper_methods.rb +88 -0
- data/lib/usps_flags/helpers.rb +163 -165
- data/lib/usps_flags/helpers/builders.rb +92 -85
- data/lib/usps_flags/helpers/spec_arrows.rb +127 -123
- data/lib/usps_flags/helpers/valid_flags.rb +45 -41
- data/lib/usps_flags/rational.rb +35 -0
- data/spec/usps_flags/config_spec.rb +17 -10
- data/spec/usps_flags/core_spec.rb +31 -31
- data/spec/usps_flags/generate_spec.rb +76 -73
- data/spec/usps_flags/helpers_spec.rb +8 -8
- data/spec/usps_flags/rational_spec.rb +17 -0
- data/spec/usps_flags_spec.rb +19 -21
- data/usps_flags.gemspec +7 -6
- metadata +34 -10
- data/lib/rational.rb +0 -39
- data/lib/usps_flags/generate/private.rb +0 -199
- data/spec/rational_spec.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a401780854a7517c7b211d59ae8c64d99f2190ece54927c9db84fea2bf33957
|
4
|
+
data.tar.gz: cd332320e247bd219bf094a72ab6c31a57fb642fefdc3cab889a4fb26b32cfc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7d4c6dd949fb0402e768a3347610cf417c2926eddbb99fe319721bb4d09595d2f9886b52bcbb88728dfa6b1d556d839e992e01b4c70a62a0ceef997996f81e4
|
7
|
+
data.tar.gz: 0d4ab1879a6d9fc1616a8fd7b1532dd50900a824d39b958679fecbc05ab8966a64d8bb48aa5ff505d5a43ce5eb4dd764b030c0063f4fba9e4ced7ab3c1e27ece
|
data/.rubocop.yml
CHANGED
@@ -2,9 +2,11 @@ require: rubocop-rspec
|
|
2
2
|
AllCops:
|
3
3
|
TargetRubyVersion: 2.5
|
4
4
|
Exclude:
|
5
|
+
- lib/output/*
|
5
6
|
- tmp/**/*
|
7
|
+
- vendor/**/*
|
6
8
|
|
7
|
-
Layout/
|
9
|
+
Layout/IndentFirstHashElement:
|
8
10
|
EnforcedStyle: consistent
|
9
11
|
Layout/AccessModifierIndentation:
|
10
12
|
EnforcedStyle: outdent
|
@@ -24,6 +26,8 @@ Layout/SpaceInsideHashLiteralBraces:
|
|
24
26
|
EnforcedStyleForEmptyBraces: no_space
|
25
27
|
Layout/SpaceInsideArrayLiteralBrackets:
|
26
28
|
EnforcedStyle: no_space
|
29
|
+
Layout/EndAlignment:
|
30
|
+
EnforcedStyleAlignWith: start_of_line
|
27
31
|
|
28
32
|
Lint/UnusedMethodArgument:
|
29
33
|
Enabled: true
|
@@ -34,12 +38,6 @@ Metrics/BlockLength:
|
|
34
38
|
Exclude:
|
35
39
|
- 'spec/**/*.rb'
|
36
40
|
Metrics/LineLength:
|
37
|
-
Exclude:
|
38
|
-
- 'spec/**/*.rb'
|
39
|
-
Max: 100
|
40
|
-
Metrics/LineLength:
|
41
|
-
Include:
|
42
|
-
- 'spec/**/*.rb'
|
43
41
|
Max: 120
|
44
42
|
Metrics/MethodLength:
|
45
43
|
Enabled: true
|
@@ -53,11 +51,19 @@ Metrics/CyclomaticComplexity:
|
|
53
51
|
Metrics/AbcSize:
|
54
52
|
Enabled: true
|
55
53
|
|
56
|
-
|
57
|
-
Enabled:
|
54
|
+
Naming/UncommunicativeMethodParamName:
|
55
|
+
Enabled: false
|
56
|
+
Naming/AccessorMethodName:
|
57
|
+
Enabled: false
|
58
58
|
|
59
59
|
RSpec/MessageSpies:
|
60
60
|
EnforcedStyle: receive
|
61
|
+
RSpec/InstanceVariable:
|
62
|
+
Enabled: false
|
63
|
+
RSpec/NestedGroups:
|
64
|
+
Enabled: false
|
65
|
+
RSpec/ExampleLength:
|
66
|
+
Enabled: false
|
61
67
|
|
62
68
|
Style/Documentation:
|
63
69
|
Enabled: false
|
@@ -73,12 +79,17 @@ Style/ClassCheck:
|
|
73
79
|
Enabled: true
|
74
80
|
Style/GuardClause:
|
75
81
|
Enabled: true
|
82
|
+
Style/ClassAndModuleChildren:
|
83
|
+
EnforcedStyle: nested
|
84
|
+
Style/GlobalVars:
|
85
|
+
Exclude:
|
86
|
+
- 'spec/**/*.rb'
|
87
|
+
Style/ParallelAssignment:
|
88
|
+
Enabled: false
|
76
89
|
|
77
90
|
Security/Eval:
|
78
91
|
Enabled: true
|
79
92
|
Security/JSONLoad:
|
80
93
|
Enabled: true
|
81
|
-
Security/JSONLoad:
|
82
|
-
Enabled: true
|
83
94
|
Security/YAMLLoad:
|
84
95
|
Enabled: true
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
usps_flags (0.5.
|
4
|
+
usps_flags (0.5.1)
|
5
5
|
file_utils (~> 1.1, >= 1.1.2)
|
6
6
|
mini_magick (~> 4.8, >= 4.8.0)
|
7
7
|
rubyzip (~> 1.2, >= 1.2.1)
|
@@ -41,6 +41,8 @@ GEM
|
|
41
41
|
rainbow (>= 2.2.2, < 4.0)
|
42
42
|
ruby-progressbar (~> 1.7)
|
43
43
|
unicode-display_width (>= 1.4.0, < 1.7)
|
44
|
+
rubocop-rspec (1.33.0)
|
45
|
+
rubocop (>= 0.60.0)
|
44
46
|
ruby-progressbar (1.10.1)
|
45
47
|
rubyzip (1.2.3)
|
46
48
|
simplecov (0.15.1)
|
@@ -56,7 +58,8 @@ PLATFORMS
|
|
56
58
|
DEPENDENCIES
|
57
59
|
rake (~> 12.2, >= 12.2.1)
|
58
60
|
rspec (~> 3.7, >= 3.7.0)
|
59
|
-
rubocop (~> 0.
|
61
|
+
rubocop (~> 0.71, >= 0.71.0)
|
62
|
+
rubocop-rspec (~> 1.30, >= 1.30.0)
|
60
63
|
simplecov (~> 0.15, >= 0.15.1)
|
61
64
|
usps_flags!
|
62
65
|
|
data/README.md
CHANGED
@@ -125,6 +125,12 @@ flag = USPSFlags.new do |f|
|
|
125
125
|
f.png_file = "/path/to/png/output.png"
|
126
126
|
end
|
127
127
|
|
128
|
+
flag = USPSFlags.new(
|
129
|
+
type: "LtC", scale: 3, field: false, trim: true,
|
130
|
+
svg_file: "/path/to/svg/output.svg",
|
131
|
+
png_file: "/path/to/png/output.png"
|
132
|
+
)
|
133
|
+
|
128
134
|
flag.svg #=> Generates SVG file at "/path/to/svg/output.svg"
|
129
135
|
flag.png #=> Generates PNG file at "/path/to/png/output.png"
|
130
136
|
```
|
data/lib/usps_flags.rb
CHANGED
@@ -1,33 +1,28 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
#
|
3
|
+
# Main module for the namespace.
|
4
4
|
#
|
5
5
|
# @author Julian Fiander
|
6
6
|
# @since 0.1.5
|
7
7
|
class USPSFlags
|
8
|
+
MODULES ||= {
|
9
|
+
'usps_flags' => %w[rational config helpers core generate errors],
|
10
|
+
'usps_flags/helpers' => %w[builders spec_arrows],
|
11
|
+
'usps_flags/core' => %w[
|
12
|
+
icons ensign field footer headers pennant tridents trident_specs trident_spec us wheel
|
13
|
+
],
|
14
|
+
'usps_flags/generate' => %w[flag]
|
15
|
+
}.freeze
|
16
|
+
|
8
17
|
require 'fileutils'
|
9
18
|
require 'zip'
|
10
19
|
require 'mini_magick'
|
11
|
-
require 'rational'
|
12
|
-
|
13
|
-
%w[config helpers core generate errors].each do |d|
|
14
|
-
require "usps_flags/#{d}"
|
15
|
-
end
|
16
|
-
|
17
|
-
%w[builders spec_arrows].each do |d|
|
18
|
-
require "usps_flags/helpers/#{d}"
|
19
|
-
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
require "usps_flags/generate/#{d}"
|
27
|
-
end
|
28
|
-
|
29
|
-
class << self
|
30
|
-
attr_accessor :configuration
|
21
|
+
MODULES.each do |parent, bases|
|
22
|
+
bases.each do |base|
|
23
|
+
res = require("#{parent}/#{base}")
|
24
|
+
puts "#{parent}/#{base}: #{res}" if ENV['VERBOSE_REQUIRE'] == 'true'
|
25
|
+
end
|
31
26
|
end
|
32
27
|
|
33
28
|
# Configuration accessor.
|
@@ -38,7 +33,7 @@ class USPSFlags
|
|
38
33
|
# Configuration constructor.
|
39
34
|
def self.configure
|
40
35
|
yield(configuration) if block_given?
|
41
|
-
|
36
|
+
ensure_directories
|
42
37
|
@configuration
|
43
38
|
end
|
44
39
|
|
@@ -46,9 +41,9 @@ class USPSFlags
|
|
46
41
|
#
|
47
42
|
# @private
|
48
43
|
def self.ensure_directories
|
49
|
-
|
50
|
-
|
51
|
-
|
44
|
+
get_dir_configs
|
45
|
+
prepare_dir_configs
|
46
|
+
prepare_flags_dir
|
52
47
|
::FileUtils.mkdir_p(USPSFlags.configuration.log_path)
|
53
48
|
end
|
54
49
|
|
@@ -56,12 +51,8 @@ class USPSFlags
|
|
56
51
|
#
|
57
52
|
# @private
|
58
53
|
def self.get_dir_configs
|
59
|
-
@dirs = USPSFlags.configuration.
|
60
|
-
|
61
|
-
map(&:to_s).
|
62
|
-
map { |v| v.match(/.*?_dir/) }.
|
63
|
-
reject! { |v| v.nil? }.
|
64
|
-
map(&:to_s)
|
54
|
+
@dirs = USPSFlags.configuration.instance_variables.map(&:to_s)
|
55
|
+
.map { |v| v.match(/.*?_dir/) }.compact.map(&:to_s)
|
65
56
|
end
|
66
57
|
|
67
58
|
# Ensures that directories exist (and are cleared, if configured).
|
@@ -98,14 +89,14 @@ class USPSFlags
|
|
98
89
|
#
|
99
90
|
# flag.svg #=> Generates SVG file at "/path/to/svg/output.svg"
|
100
91
|
# flag.png #=> Generates PNG file at "/path/to/png/output.png"
|
101
|
-
def initialize
|
102
|
-
@type =
|
103
|
-
@svg_file =
|
104
|
-
@png_file =
|
105
|
-
@scale =
|
106
|
-
@field =
|
107
|
-
@trim =
|
108
|
-
yield
|
92
|
+
def initialize(options = {})
|
93
|
+
@type = options[:type]
|
94
|
+
@svg_file = options[:svg_file]
|
95
|
+
@png_file = options[:png_file]
|
96
|
+
@scale = options[:scale]
|
97
|
+
@field = options[:field]
|
98
|
+
@trim = options[:trim]
|
99
|
+
yield(self) if block_given?
|
109
100
|
end
|
110
101
|
|
111
102
|
# Constructor accessors.
|
@@ -122,8 +113,8 @@ class USPSFlags
|
|
122
113
|
#
|
123
114
|
# @return [String] Returns the SVG file output path, or the svg data if no path was specified.
|
124
115
|
def svg
|
125
|
-
svg = USPSFlags::Generate.svg(
|
126
|
-
|
116
|
+
svg = USPSFlags::Generate.svg(type, outfile: svg_file, scale: scale, field: field)
|
117
|
+
svg_file.nil? || svg_file == '' ? svg : svg_file
|
127
118
|
end
|
128
119
|
|
129
120
|
# Generates the constructed file as PNG.
|
@@ -132,12 +123,12 @@ class USPSFlags
|
|
132
123
|
#
|
133
124
|
# @return [String] Returns the SVG file output path.
|
134
125
|
def png
|
135
|
-
raise USPSFlags::Errors::PNGGenerationError, 'A path must be set with png_file.' if
|
126
|
+
raise USPSFlags::Errors::PNGGenerationError, 'A path must be set with png_file.' if png_file.nil?
|
136
127
|
|
137
|
-
svg_file_storage =
|
128
|
+
svg_file_storage = svg_file
|
138
129
|
self.svg_file = ''
|
139
|
-
USPSFlags::Generate.png(
|
130
|
+
USPSFlags::Generate.png(svg, outfile: png_file, trim: trim)
|
140
131
|
self.svg_file = svg_file_storage
|
141
|
-
|
132
|
+
png_file
|
142
133
|
end
|
143
134
|
end
|
data/lib/usps_flags/config.rb
CHANGED
@@ -1,108 +1,110 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
3
|
# Container class for configuration values.
|
4
|
-
class USPSFlags
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
class USPSFlags
|
5
|
+
class Config
|
6
|
+
BLUE ||= '#012169'.freeze
|
7
|
+
RED ||= '#E4002B'.freeze
|
8
|
+
GOLD ||= '#FFBF3F'.freeze
|
9
|
+
OLD_GLORY_BLUE ||= '#041E42'.freeze
|
10
|
+
OLD_GLORY_RED ||= '#BF0D3E'.freeze
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
# Base measurements for most flags, before scaling
|
13
|
+
BASE_FLY ||= 3072
|
14
|
+
BASE_HOIST ||= BASE_FLY * 2 / 3
|
15
|
+
FRACTION_SCALE ||= 85
|
15
16
|
|
16
|
-
|
17
|
+
attr_accessor :flags_dir, :clear
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
# Configuration constructor
|
20
|
+
#
|
21
|
+
# @param [String] flag_dir The path to the flags directory.
|
22
|
+
# @param [Boolean] clear Whether to clear out the specified flags_dir.
|
23
|
+
def initialize
|
24
|
+
get_defaults
|
25
|
+
yield self if block_given?
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
# Base configuration values for trident insignia.
|
29
|
+
#
|
30
|
+
# All other values are derived from these, or directly from the constant sizes.
|
31
|
+
#
|
32
|
+
# @return [Hash] RThe configuration values for tridents.
|
33
|
+
def trident
|
34
|
+
{
|
35
|
+
height: trident_heights, center_point: BASE_FLY / 2,
|
36
|
+
width: USPSFlags::Config::BASE_FLY * 5 / 32, bar_width: bar_width,
|
37
|
+
hash_width: USPSFlags::Config::BASE_FLY * 47 / 528
|
38
|
+
}.merge(spikes_config).merge(delta_config).merge(circle_config)
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
41
|
+
# Height values for trident insignia.
|
42
|
+
#
|
43
|
+
# @return [Hash] The height values for tridents.
|
44
|
+
def trident_heights
|
45
|
+
{
|
46
|
+
s: USPSFlags::Config::BASE_HOIST / 2,
|
47
|
+
d: USPSFlags::Config::BASE_HOIST * 5 / 8,
|
48
|
+
stf: USPSFlags::Config::BASE_HOIST * 3 / 4,
|
49
|
+
n: USPSFlags::Config::BASE_HOIST * 3 / 4
|
50
|
+
}
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
53
|
+
# Alias for the directory to store generated log files.
|
54
|
+
#
|
55
|
+
# @return [String] The current path to the logs directory.
|
56
|
+
def log_path
|
57
|
+
if defined?(::Rails)
|
58
|
+
"#{::Rails.root}/log"
|
59
|
+
else
|
60
|
+
"#{USPSFlags.configuration.flags_dir}/log"
|
61
|
+
end
|
60
62
|
end
|
61
|
-
end
|
62
63
|
|
63
|
-
private
|
64
|
+
private
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
def get_defaults
|
67
|
+
@flags_dir = if defined?(::Rails)
|
68
|
+
"#{::Rails.root}/app/assets/images/usps-flags"
|
69
|
+
else
|
70
|
+
"#{File.dirname(__dir__)}/output"
|
71
|
+
end
|
72
|
+
@use_larger_tridents = true
|
73
|
+
@clear = false
|
70
74
|
end
|
71
|
-
@use_larger_tridents = true
|
72
|
-
@clear = false
|
73
|
-
end
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
76
|
+
def center_point_height
|
77
|
+
USPSFlags::Config::BASE_FLY / 48 * 23 / 8
|
78
|
+
end
|
78
79
|
|
79
|
-
|
80
|
-
|
81
|
-
|
80
|
+
def side_point_height
|
81
|
+
USPSFlags::Config::BASE_FLY / 48 * 21 / 8
|
82
|
+
end
|
82
83
|
|
83
|
-
|
84
|
-
|
85
|
-
|
84
|
+
def bar_width
|
85
|
+
USPSFlags::Config::BASE_FLY / 48 * 5 / 4
|
86
|
+
end
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
88
|
+
def spikes_config
|
89
|
+
{
|
90
|
+
center_point_height: center_point_height, side_point_height: side_point_height,
|
91
|
+
main_point_barb: USPSFlags::Config::BASE_HOIST / 82,
|
92
|
+
crossbar_from_top: USPSFlags::Config::BASE_HOIST / 4 + bar_width / 5,
|
93
|
+
side_spike_height: USPSFlags::Config::BASE_HOIST / 4 - side_point_height - bar_width * 3 / 5
|
94
|
+
}
|
95
|
+
end
|
95
96
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
97
|
+
def delta_config
|
98
|
+
{
|
99
|
+
delta_height: USPSFlags::Config::BASE_FLY * 33 / 240, delta_gap_height: USPSFlags::Config::BASE_FLY / 16,
|
100
|
+
delta_gap_width: bar_width * 5 / 4, delta_width: USPSFlags::Config::BASE_FLY * 43 / 768,
|
101
|
+
delta_from_bottom: USPSFlags::Config::BASE_HOIST * 10 / 64, delta_gap_scale: 0.40,
|
102
|
+
delta_gap_x: USPSFlags::Config::BASE_HOIST * 144 / 128, delta_gap_y: USPSFlags::Config::BASE_HOIST * 221 / 256
|
103
|
+
}
|
104
|
+
end
|
104
105
|
|
105
|
-
|
106
|
-
|
106
|
+
def circle_config
|
107
|
+
{ circle_height_adj: USPSFlags::Config::BASE_FLY / 800 }
|
108
|
+
end
|
107
109
|
end
|
108
110
|
end
|