lib/usps_flags.rb in usps_flags-0.3.10 vs lib/usps_flags.rb in usps_flags-0.3.11
- old
+ new
@@ -27,10 +27,37 @@
# Dir['./lib/usps_flags/helpers/**'].map { |d| d.split("/").last.split(".rb").first }
%w[builders spec_arrows].each do |d|
require "usps_flags/helpers/#{d}"
end
+ class << self
+ attr_accessor :configuration
+ end
+
+ # Configuration accessor.
+ def self.configuration
+ @configuration ||= USPSFlags::Config.new
+ end
+
+ # Configuration constructor.
+ def self.configure
+ yield(configuration)
+ self.ensure_directories
+ @configuration
+ end
+
+ # Ensures the directory structure exists.
+ #
+ # @private
+ def self.ensure_directories
+ ::FileUtils.rm_rf(@configuration.flags_dir) if @configuration.clear
+ ::FileUtils.mkdir_p("#{@configuration.flags_dir}/PNG/insignia")
+ ::FileUtils.mkdir_p("#{@configuration.flags_dir}/SVG/insignia")
+ ::FileUtils.mkdir_p("#{@configuration.flags_dir}/ZIP")
+ ::FileUtils.mkdir_p(USPSFlags.configuration.log_path)
+ end
+
# Constructor for individual flags.
#
# @example Generate insignia at default scale for Lt/C
# flag = USPSFlags.new do |f|
# f.type = "LtC"
@@ -51,46 +78,18 @@
@field = nil
@trim = nil
yield self if block_given?
end
- # Constructor accessor for the flag type.
+ # Constructor accessors.
#
# @param [String] type The type of flag to generate.
- # @return [String]
- attr_accessor :type
-
- # Constructor accessor for the SVG file output path.
- #
# @param [String] svg_file The SVG file output path.
- # @return [String] Returns the current (or updated) SVG file output path.
- attr_accessor :svg_file
-
- # Constructor accessor for the PNG file output path.
- #
# @param [String] png_file The PNG file output path.
- # @return [String] Returns the current (or updated) PNG file output path.
- attr_accessor :png_file
-
- # Constructor accessor for the image scale divisor factor.
- #
- # Available options are Float between 0 and 1, or Integer above 1.
- #
# @param [Integer, Float] scale The scale divisor factor.
- # @return [Integer, Float] Returns the current (or updated) scaling factor.
- attr_accessor :scale
-
- # Constructor accessor for whether to generate the flag field (including any border).
- #
# @param [Boolean] field The field setting.
- # @return [Boolean] Returns the current (or updated) setting.
- attr_accessor :field
-
- # Constructor accessor for whether to trim the generated PNG file of excess transparency.
- #
# @param [Boolean] trim The trim setting.
- # @return [String] Returns the current (or updated) setting.
- attr_accessor :trim
+ attr_accessor :type, :svg_file, :png_file, :scale, :field, :trim
# Generates the constructed file as SVG.
#
# @return [String] Returns the SVG file output path, or the svg data if no path was specified.
def svg