usps_flags 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +22 -11
  3. data/.travis.yml +1 -1
  4. data/Gemfile.lock +5 -2
  5. data/README.md +6 -0
  6. data/lib/usps_flags.rb +35 -44
  7. data/lib/usps_flags/config.rb +89 -87
  8. data/lib/usps_flags/core.rb +44 -42
  9. data/lib/usps_flags/core/ensign.rb +53 -49
  10. data/lib/usps_flags/core/field.rb +96 -92
  11. data/lib/usps_flags/core/footer.rb +9 -5
  12. data/lib/usps_flags/core/headers.rb +58 -48
  13. data/lib/usps_flags/core/icons.rb +11 -7
  14. data/lib/usps_flags/core/icons/anchor.rb +62 -56
  15. data/lib/usps_flags/core/icons/binoculars.rb +21 -15
  16. data/lib/usps_flags/core/icons/lighthouse.rb +28 -22
  17. data/lib/usps_flags/core/icons/star.rb +21 -15
  18. data/lib/usps_flags/core/icons/trident.rb +136 -127
  19. data/lib/usps_flags/core/icons/trident_parts/hashes.rb +62 -55
  20. data/lib/usps_flags/core/icons/trumpet.rb +34 -28
  21. data/lib/usps_flags/core/pennant.rb +50 -46
  22. data/lib/usps_flags/core/trident_spec.rb +135 -131
  23. data/lib/usps_flags/core/trident_specs.rb +11 -7
  24. data/lib/usps_flags/core/trident_specs/base.rb +36 -26
  25. data/lib/usps_flags/core/trident_specs/circle.rb +36 -30
  26. data/lib/usps_flags/core/trident_specs/delta.rb +41 -30
  27. data/lib/usps_flags/core/trident_specs/header.rb +56 -50
  28. data/lib/usps_flags/core/trident_specs/horizontal.rb +80 -0
  29. data/lib/usps_flags/core/trident_specs/long.rb +41 -25
  30. data/lib/usps_flags/core/trident_specs/overlay.rb +40 -0
  31. data/lib/usps_flags/core/trident_specs/short.rb +30 -156
  32. data/lib/usps_flags/core/trident_specs/vertical.rb +108 -0
  33. data/lib/usps_flags/core/tridents.rb +54 -50
  34. data/lib/usps_flags/core/us.rb +40 -44
  35. data/lib/usps_flags/core/wheel.rb +7 -3
  36. data/lib/usps_flags/errors.rb +25 -23
  37. data/lib/usps_flags/generate.rb +111 -107
  38. data/lib/usps_flags/generate/flag.rb +160 -157
  39. data/lib/usps_flags/generate/generator_methods.rb +139 -0
  40. data/lib/usps_flags/generate/helper_methods.rb +88 -0
  41. data/lib/usps_flags/helpers.rb +163 -165
  42. data/lib/usps_flags/helpers/builders.rb +92 -85
  43. data/lib/usps_flags/helpers/spec_arrows.rb +127 -123
  44. data/lib/usps_flags/helpers/valid_flags.rb +45 -41
  45. data/lib/usps_flags/rational.rb +35 -0
  46. data/spec/usps_flags/config_spec.rb +17 -10
  47. data/spec/usps_flags/core_spec.rb +31 -31
  48. data/spec/usps_flags/generate_spec.rb +76 -73
  49. data/spec/usps_flags/helpers_spec.rb +8 -8
  50. data/spec/usps_flags/rational_spec.rb +17 -0
  51. data/spec/usps_flags_spec.rb +19 -21
  52. data/usps_flags.gemspec +7 -6
  53. metadata +34 -10
  54. data/lib/rational.rb +0 -39
  55. data/lib/usps_flags/generate/private.rb +0 -199
  56. data/spec/rational_spec.rb +0 -19
@@ -4,60 +4,62 @@
4
4
  #
5
5
  # These methods should never need to be called directly.
6
6
  # @private
7
- class USPSFlags::Core
8
- def self.trident_spec(fly: 24, unit: 'in', scaled_border: false)
9
- USPSFlags::Core::TridentSpec.new(fly: fly, unit: unit, scaled_border: scaled_border).svg
10
- end
7
+ class USPSFlags
8
+ class Core
9
+ def self.trident_spec(fly: 24, unit: 'in', scaled_border: false)
10
+ USPSFlags::Core::TridentSpec.new(fly: fly, unit: unit, scaled_border: scaled_border).svg
11
+ end
11
12
 
12
- def self.headers(width: nil, height: nil, pennant: false, scale: nil, title: 'USPS Flag')
13
- USPSFlags::Core::Headers.new(width: width, height: height, pennant: pennant, scale: scale, title: title).svg
14
- end
13
+ def self.headers(width: nil, height: nil, pennant: false, scale: nil, title: 'USPS Flag')
14
+ USPSFlags::Core::Headers.new(width: width, height: height, pennant: pennant, scale: scale, title: title).svg
15
+ end
15
16
 
16
- def self.footer
17
- USPSFlags::Core::Footer.new.svg
18
- end
17
+ def self.footer
18
+ USPSFlags::Core::Footer.new.svg
19
+ end
19
20
 
20
- def self.field(style: :regular, color: :white, fly: USPSFlags::Config::BASE_FLY)
21
- USPSFlags::Core::Field.new(style: style, color: color, fly: fly).svg
22
- end
21
+ def self.field(style: :regular, color: :white, fly: USPSFlags::Config::BASE_FLY)
22
+ USPSFlags::Core::Field.new(style: style, color: color, fly: fly).svg
23
+ end
23
24
 
24
- def self.trident(type, color: :blue, field_color: nil)
25
- USPSFlags::Core::Icons::Trident.new(type, color: color, field_color: field_color).svg
26
- end
25
+ def self.trident(type, color: :blue, field_color: nil)
26
+ USPSFlags::Core::Icons::Trident.new(type, color: color, field_color: field_color).svg
27
+ end
27
28
 
28
- def self.anchor(color = :red)
29
- USPSFlags::Core::Icons::Anchor.new(color: color).svg
30
- end
29
+ def self.anchor(color = :red)
30
+ USPSFlags::Core::Icons::Anchor.new(color: color).svg
31
+ end
31
32
 
32
- def self.lighthouse
33
- USPSFlags::Core::Icons::Lighthouse.new.svg
34
- end
33
+ def self.lighthouse
34
+ USPSFlags::Core::Icons::Lighthouse.new.svg
35
+ end
35
36
 
36
- def self.binoculars(type = :d)
37
- USPSFlags::Core::Icons::Binoculars.new(type: type).svg
38
- end
37
+ def self.binoculars(type = :d)
38
+ USPSFlags::Core::Icons::Binoculars.new(type: type).svg
39
+ end
39
40
 
40
- def self.trumpet(type = :s)
41
- USPSFlags::Core::Icons::Trumpet.new(type: type).svg
42
- end
41
+ def self.trumpet(type = :s)
42
+ USPSFlags::Core::Icons::Trumpet.new(type: type).svg
43
+ end
43
44
 
44
- def self.pennant(type = 'cruise')
45
- USPSFlags::Core::Pennant.new(type: type).svg
46
- end
45
+ def self.pennant(type = 'cruise')
46
+ USPSFlags::Core::Pennant.new(type: type).svg
47
+ end
47
48
 
48
- def self.ensign
49
- USPSFlags::Core::Ensign.new.svg
50
- end
49
+ def self.ensign
50
+ USPSFlags::Core::Ensign.new.svg
51
+ end
51
52
 
52
- def self.star
53
- USPSFlags::Core::Icons::Star.new.svg
54
- end
53
+ def self.star
54
+ USPSFlags::Core::Icons::Star.new.svg
55
+ end
55
56
 
56
- def self.wheel
57
- USPSFlags::Core::Wheel.new.svg
58
- end
57
+ def self.wheel
58
+ USPSFlags::Core::Wheel.new.svg
59
+ end
59
60
 
60
- def self.us
61
- USPSFlags::Core::US.new.svg
61
+ def self.us
62
+ USPSFlags::Core::US.new.svg
63
+ end
62
64
  end
63
65
  end
@@ -4,65 +4,69 @@
4
4
  #
5
5
  # This class should never need to be called directly.
6
6
  # @private
7
- class USPSFlags::Core::Ensign
8
- def svg
9
- <<~SVG
10
- #{stripes}
11
- #{canton}
12
- <g transform="scale(0.3675)">
13
- <g transform="translate(1200, 600)">
14
- <g transform="rotate(-45, 693, 1500)">
15
- #{USPSFlags::Core::Icons::Anchor.new(color: :white).svg}
7
+ class USPSFlags
8
+ class Core
9
+ class Ensign
10
+ def svg
11
+ <<~SVG
12
+ #{stripes}
13
+ #{canton}
14
+ <g transform="scale(0.3675)">
15
+ <g transform="translate(1200, 600)">
16
+ <g transform="rotate(-45, 693, 1500)">
17
+ #{USPSFlags::Core::Icons::Anchor.new(color: :white).svg}
18
+ </g>
19
+ </g>
16
20
  </g>
17
- </g>
18
- </g>
19
- #{star_circle}
20
- SVG
21
- end
21
+ #{star_circle}
22
+ SVG
23
+ end
22
24
 
23
- private
25
+ private
24
26
 
25
- def stripes
26
- (0..12).map do |index|
27
- index.odd? ? white_stripe(index) : blue_stripe(index)
28
- end.join
29
- end
27
+ def stripes
28
+ (0..12).map do |index|
29
+ index.odd? ? white_stripe(index) : blue_stripe(index)
30
+ end.join
31
+ end
30
32
 
31
- def canton
32
- <<~SVG
33
- <rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY * 6 / 13}" height="1000" fill="#{USPSFlags::Config::RED}" />
34
- SVG
35
- end
33
+ def canton
34
+ <<~SVG
35
+ <rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY * 6 / 13}" height="1000" fill="#{USPSFlags::Config::RED}" />
36
+ SVG
37
+ end
36
38
 
37
- def white_stripe(index)
38
- <<~SVG
39
- <rect x="#{USPSFlags::Config::BASE_FLY * index / 13}" y="0" width="#{USPSFlags::Config::BASE_FLY / 13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#FFFFFF" />
40
- SVG
41
- end
39
+ def white_stripe(index)
40
+ <<~SVG
41
+ <rect x="#{USPSFlags::Config::BASE_FLY * index / 13}" y="0" width="#{USPSFlags::Config::BASE_FLY / 13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#FFFFFF" />
42
+ SVG
43
+ end
42
44
 
43
- def blue_stripe(index)
44
- <<~SVG
45
- <rect x="#{USPSFlags::Config::BASE_FLY * index / 13}" y="0" width="#{USPSFlags::Config::BASE_FLY / 13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#{USPSFlags::Config::BLUE}" />
46
- SVG
47
- end
45
+ def blue_stripe(index)
46
+ <<~SVG
47
+ <rect x="#{USPSFlags::Config::BASE_FLY * index / 13}" y="0" width="#{USPSFlags::Config::BASE_FLY / 13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#{USPSFlags::Config::BLUE}" />
48
+ SVG
49
+ end
48
50
 
49
- def star_circle
50
- svg = +''
51
+ def star_circle
52
+ svg = +''
51
53
 
52
- (0..13).each { |i| svg << rotated_star(i * (360.0 / 13)) }
54
+ (0..13).each { |i| svg << rotated_star(i * (360.0 / 13)) }
53
55
 
54
- svg
55
- end
56
+ svg
57
+ end
56
58
 
57
- def rotated_star(rotation)
58
- <<~SVG
59
- <g transform="scale(0.375)">
60
- <g transform="translate(1885, 465)">
61
- <g transform="rotate(#{rotation}, 0, 900)">
62
- #{USPSFlags::Core.star}
59
+ def rotated_star(rotation)
60
+ <<~SVG
61
+ <g transform="scale(0.375)">
62
+ <g transform="translate(1885, 465)">
63
+ <g transform="rotate(#{rotation}, 0, 900)">
64
+ #{USPSFlags::Core.star}
65
+ </g>
66
+ </g>
63
67
  </g>
64
- </g>
65
- </g>
66
- SVG
68
+ SVG
69
+ end
70
+ end
67
71
  end
68
72
  end
@@ -4,110 +4,114 @@
4
4
  #
5
5
  # This class should never need to be called directly.
6
6
  # @private
7
- class USPSFlags::Core::Field
8
- def initialize(style: :regular, color: :white, fly: USPSFlags::Config::BASE_FLY)
9
- @style = style
10
- @fly = fly
11
- border = color == :white
12
- @color_code, @past_mid_color, @past_tail_color = send("#{color}_colors")
13
- @border_svg = if border
14
- "stroke=\"#000000\" stroke-width=\"#{USPSFlags::Config::BASE_FLY / 600}\" "
15
- else
16
- ''
17
- end
7
+ class USPSFlags
8
+ class Core
9
+ class Field
10
+ def initialize(style: :regular, color: :white, fly: USPSFlags::Config::BASE_FLY)
11
+ @style = style
12
+ @fly = fly
13
+ border = color == :white
14
+ @color_code, @past_mid_color, @past_tail_color = send("#{color}_colors")
15
+ @border_svg = if border
16
+ "stroke=\"#000000\" stroke-width=\"#{USPSFlags::Config::BASE_FLY / 600}\" "
17
+ else
18
+ ''
19
+ end
18
20
 
19
- @hoist = (@fly * 2) / 3
20
- end
21
+ @hoist = (@fly * 2) / 3
22
+ end
21
23
 
22
- def svg
23
- case @style
24
- when :regular
25
- regular_field
26
- when :swallowtail
27
- swallowtail_field
28
- when :past
29
- past_field
30
- end
31
- end
24
+ def svg
25
+ case @style
26
+ when :regular
27
+ regular_field
28
+ when :swallowtail
29
+ swallowtail_field
30
+ when :past
31
+ past_field
32
+ end
33
+ end
32
34
 
33
- private
35
+ private
34
36
 
35
- def white_colors
36
- ['#FFFFFF', USPSFlags::Config::BLUE, USPSFlags::Config::RED]
37
- end
37
+ def white_colors
38
+ ['#FFFFFF', USPSFlags::Config::BLUE, USPSFlags::Config::RED]
39
+ end
38
40
 
39
- def red_colors
40
- [USPSFlags::Config::RED, '#FFFFFF', USPSFlags::Config::BLUE]
41
- end
41
+ def red_colors
42
+ [USPSFlags::Config::RED, '#FFFFFF', USPSFlags::Config::BLUE]
43
+ end
42
44
 
43
- def blue_colors
44
- [USPSFlags::Config::BLUE, '#FFFFFF', USPSFlags::Config::RED]
45
- end
45
+ def blue_colors
46
+ [USPSFlags::Config::BLUE, '#FFFFFF', USPSFlags::Config::RED]
47
+ end
46
48
 
47
- def regular_field
48
- <<~SVG
49
- <path d="M 0 0
50
- l #{@fly} 0
51
- l 0 #{@hoist}
52
- l -#{@fly} 0
53
- l 0 -#{@hoist}
54
- " fill="#{@color_code}" #{@border_svg}/>
55
- SVG
56
- end
49
+ def regular_field
50
+ <<~SVG
51
+ <path d="M 0 0
52
+ l #{@fly} 0
53
+ l 0 #{@hoist}
54
+ l -#{@fly} 0
55
+ l 0 -#{@hoist}
56
+ " fill="#{@color_code}" #{@border_svg}/>
57
+ SVG
58
+ end
57
59
 
58
- def swallowtail_field
59
- <<~SVG
60
- <path d="M #{USPSFlags::Config::BASE_FLY / 1200} #{USPSFlags::Config::BASE_FLY / 1800}
61
- l #{@fly} #{@hoist / 6}
62
- l -#{@fly / 5} #{@hoist / 3}
63
- l #{@fly / 5} #{@hoist / 3}
64
- l -#{@fly} #{@hoist / 6} z
65
- " fill="#FFFFFF" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
66
- SVG
67
- end
60
+ def swallowtail_field
61
+ <<~SVG
62
+ <path d="M #{USPSFlags::Config::BASE_FLY / 1200} #{USPSFlags::Config::BASE_FLY / 1800}
63
+ l #{@fly} #{@hoist / 6}
64
+ l -#{@fly / 5} #{@hoist / 3}
65
+ l #{@fly / 5} #{@hoist / 3}
66
+ l -#{@fly} #{@hoist / 6} z
67
+ " fill="#FFFFFF" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
68
+ SVG
69
+ end
68
70
 
69
- def past_field
70
- <<~SVG
71
- <g transform="translate(#{USPSFlags::Config::BASE_FLY / 1200}, #{USPSFlags::Config::BASE_FLY / 1800})">
72
- <path d="M 0 #{USPSFlags::Config::BASE_FLY / 600} #{past_line_one}" fill="#{@color_code}" />
73
- <path d="M #{@fly / 2} #{@hoist / 12} #{past_line_two}" fill="#{@past_mid_color}" />
74
- <path d="M #{@fly * 3 / 4} #{@hoist * 3 / 24} #{past_line_three}" fill="#{@past_tail_color}" />
75
- <path d="M 0 0 #{past_line_four} z" fill="none" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
76
- </g>
77
- SVG
78
- end
71
+ def past_field
72
+ <<~SVG
73
+ <g transform="translate(#{USPSFlags::Config::BASE_FLY / 1200}, #{USPSFlags::Config::BASE_FLY / 1800})">
74
+ <path d="M 0 #{USPSFlags::Config::BASE_FLY / 600} #{past_line_one}" fill="#{@color_code}" />
75
+ <path d="M #{@fly / 2} #{@hoist / 12} #{past_line_two}" fill="#{@past_mid_color}" />
76
+ <path d="M #{@fly * 3 / 4} #{@hoist * 3 / 24} #{past_line_three}" fill="#{@past_tail_color}" />
77
+ <path d="M 0 0 #{past_line_four} z" fill="none" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
78
+ </g>
79
+ SVG
80
+ end
79
81
 
80
- def past_line_one
81
- <<~SVG
82
- l #{@fly / 2} #{@hoist / 12}
83
- l 0 #{@hoist * 10 / 12}
84
- l -#{@fly / 2} #{@hoist / 12}
85
- SVG
86
- end
82
+ def past_line_one
83
+ <<~SVG
84
+ l #{@fly / 2} #{@hoist / 12}
85
+ l 0 #{@hoist * 10 / 12}
86
+ l -#{@fly / 2} #{@hoist / 12}
87
+ SVG
88
+ end
87
89
 
88
- def past_line_two
89
- <<~SVG
90
- l #{@fly / 4} #{@hoist / 24}
91
- l 0 #{@hoist * 9 / 12}
92
- l -#{@fly / 4} #{@hoist / 24}
93
- SVG
94
- end
90
+ def past_line_two
91
+ <<~SVG
92
+ l #{@fly / 4} #{@hoist / 24}
93
+ l 0 #{@hoist * 9 / 12}
94
+ l -#{@fly / 4} #{@hoist / 24}
95
+ SVG
96
+ end
95
97
 
96
- def past_line_three
97
- <<~SVG
98
- l #{@fly / 4} #{@hoist / 24}
99
- l -#{@fly / 5} #{@hoist / 3}
100
- l #{@fly / 5} #{@hoist / 3}
101
- l -#{@fly / 4} #{@hoist / 24}
102
- SVG
103
- end
98
+ def past_line_three
99
+ <<~SVG
100
+ l #{@fly / 4} #{@hoist / 24}
101
+ l -#{@fly / 5} #{@hoist / 3}
102
+ l #{@fly / 5} #{@hoist / 3}
103
+ l -#{@fly / 4} #{@hoist / 24}
104
+ SVG
105
+ end
104
106
 
105
- def past_line_four
106
- <<~SVG
107
- l #{@fly} #{@hoist / 6}
108
- l -#{@fly / 5} #{@hoist / 3}
109
- l #{@fly / 5} #{@hoist / 3}
110
- l -#{@fly} #{@hoist / 6}
111
- SVG
107
+ def past_line_four
108
+ <<~SVG
109
+ l #{@fly} #{@hoist / 6}
110
+ l -#{@fly / 5} #{@hoist / 3}
111
+ l #{@fly / 5} #{@hoist / 3}
112
+ l -#{@fly} #{@hoist / 6}
113
+ SVG
114
+ end
115
+ end
112
116
  end
113
117
  end
@@ -4,10 +4,14 @@
4
4
  #
5
5
  # This class should never need to be called directly.
6
6
  # @private
7
- class USPSFlags::Core::Footer
8
- def svg
9
- <<~SVG
10
- </svg>
11
- SVG
7
+ class USPSFlags
8
+ class Core
9
+ class Footer
10
+ def svg
11
+ <<~SVG
12
+ </svg>
13
+ SVG
14
+ end
15
+ end
12
16
  end
13
17
  end