Class: Svgeez::Builder
- Inherits:
-
Object
- Object
- Svgeez::Builder
- Defined in:
- lib/svgeez/builder.rb
Constant Summary collapse
- SOURCE_IS_DESTINATION_MESSAGE =
"Setting `source` and `destination` to the same path isn't allowed!".freeze
- SOURCE_DOES_NOT_EXIST =
'Provided `source` folder does not exist.'.freeze
- NO_SVGS_IN_SOURCE_MESSAGE =
'No SVGs were found in `source` folder.'.freeze
Instance Attribute Summary collapse
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#build ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#initialize(options = {}) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(options = {}) ⇒ Builder
Returns a new instance of Builder.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/svgeez/builder.rb', line 9 def initialize( = {}) @source = Source.new() @destination = Destination.new() @svgo = .fetch('svgo', false) @prefix = .fetch('prefix', @destination.file_id) raise SOURCE_IS_DESTINATION_MESSAGE if source_is_destination? raise SOURCE_DOES_NOT_EXIST unless source_exists? rescue RuntimeError => exception logger.error exception. exit end |
Instance Attribute Details
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
7 8 9 |
# File 'lib/svgeez/builder.rb', line 7 def destination @destination end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
7 8 9 |
# File 'lib/svgeez/builder.rb', line 7 def prefix @prefix end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
7 8 9 |
# File 'lib/svgeez/builder.rb', line 7 def source @source end |
Instance Method Details
#build ⇒ Object
rubocop:disable Metrics/AbcSize
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/svgeez/builder.rb', line 23 def build raise NO_SVGS_IN_SOURCE_MESSAGE if source_is_empty? logger.info "Generating sprite at `#{destination_file_path}` from #{source_files_count} SVG#{'s' if source_files_count > 1}..." # Make destination folder FileUtils.mkdir_p(destination.folder_path) # Write the file File.open(destination_file_path, 'w') do |file| file.write destination_file_contents end logger.info "Successfully generated sprite at `#{destination_file_path}`." rescue RuntimeError => exception logger.warn exception. end |