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 |
# File 'lib/magick_minimalistic/sanitize.rb', line 12 def self.attributes(attrs) config = "" attrs.each do |key, value| unless /^(gravity|crop|resize)$/ =~ key puts 'The key is not a valid one' next end value = type(key, value) if /^(gravity)$/ =~ key value = geometry(key, value) if /^(crop|resize)$/ =~ key config += Option.send(key, value) end config 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
26 27 28 29 30 31 32 33 |
# File 'lib/magick_minimalistic/sanitize.rb', line 26 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
35 36 37 38 39 40 41 42 43 |
# File 'lib/magick_minimalistic/sanitize.rb', line 35 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 |