class Pxlsrt::Helpers
Methods not having to do with image or color manipulation.
Public Class Methods
checkOptions(options, rules)
click to toggle source
Checks if supplied options follow the rules.
# File lib/pxlsrt/helpers.rb, line 37 def self.checkOptions(options, rules) match=true for o in options.keys o_match=false if rules[o].class==Array if rules[o].include?(options[o]) o_match=true else for r in 0...rules[o].length if rules[o][r].class==Hash for n in rules[o][r][:class] if n==options[o].class o_match=match break end end end if o_match==true break end end end elsif rules[o] == :anything o_match = true end match=(match and o_match) if match==false break end end return match end
contented(c)
click to toggle source
Determines if a value has content.
# File lib/pxlsrt/helpers.rb, line 7 def self.contented(c) return c != nil end
cyan(what)
click to toggle source
Used to output a cyan string to the terminal.
# File lib/pxlsrt/helpers.rb, line 17 def self.cyan(what) return "\e[36m#{what}\e[0m" end
error(what)
click to toggle source
Prints an error message.
# File lib/pxlsrt/helpers.rb, line 95 def self.error(what) puts "#{Pxlsrt::Helpers.red("pxlsrt")} #{what}" end
green(what)
click to toggle source
Used to output a green string to the terminal.
# File lib/pxlsrt/helpers.rb, line 27 def self.green(what) return "\e[32m#{what}\e[0m" end
handlePixelSort(band, o)
click to toggle source
Pixel sorting helper to eliminate repetition.
# File lib/pxlsrt/helpers.rb, line 71 def self.handlePixelSort(band, o) if (o[:reverse].class == String and (o[:reverse].downcase == "reverse" or o[:reverse] == "")) or o[:reverse] == true reverse = 1 elsif o[:reverse].class == String and o[:reverse].downcase == "either" reverse = -1 else reverse = 0 end if o[:smooth] u = band.group_by { |x| x } k = u.keys else k = band end sortedBand = Pxlsrt::Colors.pixelSort( k, o[:method], reverse ) sortedBand = sortedBand.map { |x| u[x] }.flatten(1) if o[:smooth] return Pxlsrt::Lines.handleMiddlate(sortedBand, o[:middle]) end
isNumeric?(s)
click to toggle source
Determines if a string can be a float or integer.
# File lib/pxlsrt/helpers.rb, line 32 def self.isNumeric?(s) true if Float(s) rescue false end
progress(what, amount, outof)
click to toggle source
Progress indication.
# File lib/pxlsrt/helpers.rb, line 105 def self.progress(what, amount, outof) progress = (amount.to_f * 100.0 / outof.to_f).to_i if progress == 100 puts "\r#{Pxlsrt::Helpers.green("pxlsrt")} #{what} (#{Pxlsrt::Helpers.green("#{progress}%")})" else $stdout.write "\r#{Pxlsrt::Helpers.yellow("pxlsrt")} #{what} (#{Pxlsrt::Helpers.yellow("#{progress}%")})" $stdout.flush end end
red(what)
click to toggle source
Used to output a red string to the terminal.
# File lib/pxlsrt/helpers.rb, line 12 def self.red(what) return "\e[31m#{what}\e[0m" end
verbose(what)
click to toggle source
Prints something.
# File lib/pxlsrt/helpers.rb, line 100 def self.verbose(what) puts "#{Pxlsrt::Helpers.cyan("pxlsrt")} #{what}" end
yellow(what)
click to toggle source
Used to output a yellow string to the terminal.
# File lib/pxlsrt/helpers.rb, line 22 def self.yellow(what) return "\e[33m#{what}\e[0m" end