Module: Sanitize
- Included in:
- MagickMinimalistic::Configurator
- Defined in:
- lib/magick_minimalistic/sanitize.rb
Class Method Summary collapse
- .attributes(attrs) ⇒ Object
- .filename(file, type) ⇒ Object
- .geometry(key, value) ⇒ Object
- .type(key, value) ⇒ Object
Class Method Details
.attributes(attrs) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/magick_minimalistic/sanitize.rb', line 12 def self.attributes(attrs) config_hash, config_string = {}, "" puts 'There is no config to apply' unless attrs.length != -1 attrs.each do |key, value| unless /^(gravity|crop|resize)$/ =~ key puts 'The key is not a valid one' puts 'Ignoring wrong key...' next end value = type(key, value) if /^(gravity)$/ =~ key value = geometry(key, value) if /^(crop|resize)$/ =~ key config_hash[key] = value config_string += Option.send(key, value) end [config_hash, config_string] end |
.filename(file, type) ⇒ Object
2 3 4 5 6 7 8 9 10 |
# File 'lib/magick_minimalistic/sanitize.rb', line 2 def self.filename(file, type) loop do return file if type && file.is_a?(String) && File.exist?(file) return file if !type && file.is_a?(String) && file.length > 0 puts "The file -> #{file} <- doesn't exist or is not a String!" puts 'Please write a proper filename' file = gets.chomp end end |
.geometry(key, value) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/magick_minimalistic/sanitize.rb', line 29 def self.geometry(key, value) loop do return value if value.is_a?(String) && (/^\d+x\d+$/ =~ value || /^\d+%$/ =~ value) puts "The value (#{value}) for the key (#{key}) is not properly formed!" puts 'Write a valid value' value = gets.chomp end end |
.type(key, value) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/magick_minimalistic/sanitize.rb', line 38 def self.type(key, value) loop do return value if value.is_a?(String) && /^(NorthWest|North|NortEast|West|Center|East|SouthWest|South|SouthEast)$/ =~ value puts "The value (#{value}) for the key (#{key}) is not properly formed!" puts 'Write a valid value' value = gets.chomp end end |