Module: PPP

Defined in:
lib/ppp.rb,
lib/ppp/ppp.rb,
lib/ppp/version.rb

Constant Summary collapse

VERSION =
"0.1.1"

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ppp/ppp.rb', line 63

def method_missing(m, *args)
  obj = *args[0]
  obj = obj.to_s
  obj = obj.split(':')
  obj.map! {|x| x.split('<') }

  obj[0][1] = obj[0][1].underline.magenta
  obj[0] = obj[0].join("<")

  obj.flatten!

  obj[1] = obj[1].split

  obj[1][0] = obj[1][0].underline

  obj[1][1] = obj[1][1].split("=")
  obj[1][1][0] = obj[1][1][0].green

  obj[1][1][1] = (prettify(eval(obj[1][1][1].sub(">]", ""))) + ">]")
  obj[1][1] = obj[1][1].join("=")
  obj[1] = obj[1].join " "
  obj = obj.join ":"

  obj
end

Instance Method Details

#colorize_array(a) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ppp/ppp.rb', line 30

def colorize_array(a)
  out = "[ "

  a.each do |i|
    str = prettify(i)
    out << "#{str}, "
  end

  out << " ]"
  out.sub!(/,  \]/, " ]")
  out
end

#colorize_boolean(b) ⇒ Object Also known as: colorize_trueclass, colorize_falseclass



26
27
28
# File 'lib/ppp/ppp.rb', line 26

def colorize_boolean(b)
  b.to_s.cyan
end

#colorize_class(c) ⇒ Object Also known as: colorize_module



59
60
61
# File 'lib/ppp/ppp.rb', line 59

def colorize_class(c)
  c.to_s.underline.magenta
end

#colorize_fixnum(num) ⇒ Object



18
19
20
# File 'lib/ppp/ppp.rb', line 18

def colorize_fixnum(num)
  num.to_s.blue
end

#colorize_float(f) ⇒ Object



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

def colorize_float(f)
  f.to_s.magenta
end

#colorize_hash(h) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ppp/ppp.rb', line 47

def colorize_hash(h)
  str = "{ "
  h.each do |k,v|
    key = prettify(k)
    value = prettify(v)
    str << "#{key} => #{value}, "
  end
  str << " }"
  str.sub!(/,  \}/, " }")
  str
end

#colorize_string(s) ⇒ Object



14
15
16
# File 'lib/ppp/ppp.rb', line 14

def colorize_string(s)
  "#{'"'.red.bold}#{s.red}#{'"'.red.bold}"
end

#colorize_symbol(sym) ⇒ Object



43
44
45
# File 'lib/ppp/ppp.rb', line 43

def colorize_symbol(sym)
  ":#{sym}".yellow
end

#ppp(*objects) ⇒ Object



2
3
4
5
6
7
# File 'lib/ppp/ppp.rb', line 2

def ppp(*objects)
  objects.each do |o|
    str = prettify(o)
    puts str
  end
end

#prettify(object) ⇒ Object



9
10
11
12
# File 'lib/ppp/ppp.rb', line 9

def prettify(object)
  pretty = send("colorize_#{object.class.to_s.downcase}".to_sym, object)
  pretty
end