Class: Pxlsrt::Helpers

Inherits:
Object
  • Object
show all
Defined in:
lib/pxlsrt/helpers.rb

Overview

Methods not having to do with image or color manipulation.

Class Method Summary collapse

Class Method Details

.checkOptions(options, rules) ⇒ Object

Checks if supplied options follow the rules.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pxlsrt/helpers.rb', line 27

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) ⇒ Object

Determines if a value has content.



7
8
9
# File 'lib/pxlsrt/helpers.rb', line 7

def self.contented(c)
  return c != nil
end

.cyan(what) ⇒ Object

Used to output a cyan string to the terminal.



17
18
19
# File 'lib/pxlsrt/helpers.rb', line 17

def self.cyan(what)
  return "\e[36m#{what}\e[0m"
end

.error(what) ⇒ Object

Prints an error message.



85
86
87
# File 'lib/pxlsrt/helpers.rb', line 85

def self.error(what)
  puts "#{Pxlsrt::Helpers.red("pxlsrt")} #{what}"
end

.handlePixelSort(band, o) ⇒ Object

Pixel sorting helper to eliminate repetition.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/pxlsrt/helpers.rb', line 61

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) ⇒ Boolean

Determines if a string can be a float or integer.

Returns:

  • (Boolean)


22
23
24
# File 'lib/pxlsrt/helpers.rb', line 22

def self.isNumeric?(s)
  true if Float(s) rescue false
end

.red(what) ⇒ Object

Used to output a red string to the terminal.



12
13
14
# File 'lib/pxlsrt/helpers.rb', line 12

def self.red(what)
  return "\e[31m#{what}\e[0m"
end

.verbose(what) ⇒ Object

Prints something.



90
91
92
# File 'lib/pxlsrt/helpers.rb', line 90

def self.verbose(what)
  puts "#{Pxlsrt::Helpers.cyan("pxlsrt")} #{what}"
end