Sha256: f0fae7fd9eeaa8043afe8552c6061c6f414b44ed08c458ff4f1ad079ec07fbd6

Contents?: true

Size: 1.76 KB

Versions: 16

Compression:

Stored size: 1.76 KB

Contents

# Core SVG data for the file headers.
#
# This class should never need to be called directly.
# @private
class USPSFlags::Core::Headers
  def initialize(width: nil, height: nil, pennant: false, scale: nil, title: "USPS Flag")
    @width = width
    @height = height
    @title = title
    if @width.nil? || @height.nil?
      scale = 3 if scale.nil?
      @width = USPSFlags::Config::BASE_FLY / scale
      @height = (@width*Rational(2,3)).to_i

      @view_width = USPSFlags::Config::BASE_FLY
      @view_height = USPSFlags::Config::BASE_HOIST

      if pennant
        @height = @height/4
        @view_height = USPSFlags::Config::BASE_HOIST/4
      end
    else
      if scale.nil?
        @view_width = @width
        @view_height = @height
      else
        @view_width = @width * scale
        @view_height = @height * scale
      end
    end

    @generated_at = Time.now.strftime("%Y%m%d.%H%S%z")
  end

  def svg
    svg = ""
    svg << <<~SVG
      <?xml version="1.0" standalone="no"?>
      <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
      <svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="#{@width}pt" height="#{@height}pt" viewBox="0 0 #{@view_width} #{@view_height}" preserveAspectRatio="xMidYMid meet">
      <title>#{@title}</title>
      <metadata>
      <desc id="created-by">Julian Fiander</desc>
      <desc id="generated-at">#{@generated_at}</desc>
    SVG

    unless @title == "US Ensign"
      svg << <<~SVG
        <desc id="trademark-desc">This image is a registered trademark of United States Power Squadrons.</desc>
        <desc id="trademark-link">http://www.usps.org/national/itcom/trademark.html</desc>
      SVG
    end

    svg << <<~SVG
      </metadata>
    SVG

    svg
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
usps_flags-0.3.4 lib/usps_flags/core/headers.rb
usps_flags-0.3.3 lib/usps_flags/core/headers.rb
usps_flags-0.3.2 lib/usps_flags/core/headers.rb
usps_flags-0.3.1 lib/usps_flags/core/headers.rb
usps_flags-0.3.0 lib/usps_flags/core/headers.rb
usps_flags-0.2.6 lib/usps_flags/core/headers.rb
usps_flags-0.2.5 lib/usps_flags/core/headers.rb
usps_flags-0.2.4 lib/usps_flags/core/headers.rb
usps_flags-0.2.3 lib/usps_flags/core/headers.rb
usps_flags-0.2.2 lib/usps_flags/core/headers.rb
usps_flags-0.2.1 lib/usps_flags/core/headers.rb
usps_flags-0.2.0 lib/usps_flags/core/headers.rb
usps_flags-0.1.26 lib/usps_flags/core/headers.rb
usps_flags-0.1.25 lib/usps_flags/core/headers.rb
usps_flags-0.1.24 lib/usps_flags/core/headers.rb
usps_flags-0.1.23 lib/usps_flags/core/headers.rb