Module: Lll

Defined in:
lib/lll.rb

Class Method Summary collapse

Class Method Details

.display_on_separate_lines?(value) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/lll.rb', line 48

def self.display_on_separate_lines? value
  value.respond_to?(:each) && !value.is_a?(String) && !nokogiri?(value)
end

.format(output_string, colorize = true) ⇒ Object



42
43
44
45
46
# File 'lib/lll.rb', line 42

def self.format output_string, colorize = true
  string = output_string
  string =  "\e[7m" + string + "\e[0m" if colorize
  string + "lll: #{caller[2].to_s} #{Time.now.strftime('%X')} #{$using_dumb_terminal}"
end

.lll(msg, block = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/lll.rb', line 15

def self.lll msg, block = nil
  output_string = " "
  expression_value = 0
  if block
    output_string << msg + ': ' if msg
    expression_string = block.call
    expression_value = eval(expression_string, block.binding)
    output_string << expression_string + ' = '
    if defined?(AwesomePrint) && !$using_dumb_terminal
      output_string << expression_value.awesome_inspect << " \n"
    elsif display_on_separate_lines? expression_value
      output_string << " \n"
      expression_value.each { |e| output_string << ' ' << e.inspect << " \n" }
    else
      output_string << expression_value.inspect << " \n"
    end
  else
    output_string << msg if msg
    output_string << " \n"
  end

  $stderr.puts format(output_string, !$using_dumb_terminal)
  Rails.logger.debug(format(output_string)) if defined?(Rails) && Rails.logger

  expression_value
end

.nokogiri?(value) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
# File 'lib/lll.rb', line 52

def self.nokogiri? value
  return false unless defined? Nokogiri
  return value.is_a?(Nokogiri::HTML::Document) || value.is_a?(Nokogiri::XML::Element)
end