Class: Groonga::QueryLog::Analyzer::ConsoleReporter::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga/query-log/analyzer/reporter/console.rb

Constant Summary collapse

NAMES =
["black", "red", "green", "yellow",
"blue", "magenta", "cyan", "white"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Color

Returns a new instance of Color.



31
32
33
34
35
36
37
38
39
# File 'lib/groonga/query-log/analyzer/reporter/console.rb', line 31

def initialize(name, options={})
  @name = name
  @foreground = options[:foreground]
  @foreground = true if @foreground.nil?
  @intensity = options[:intensity]
  @bold = options[:bold]
  @italic = options[:italic]
  @underline = options[:underline]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



30
31
32
# File 'lib/groonga/query-log/analyzer/reporter/console.rb', line 30

def name
  @name
end

Instance Method Details

#+(other) ⇒ Object



89
90
91
# File 'lib/groonga/query-log/analyzer/reporter/console.rb', line 89

def +(other)
  MixColor.new([self, other])
end

#==(other) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/groonga/query-log/analyzer/reporter/console.rb', line 61

def ==(other)
  self.class === other and
    [name, foreground?, intensity?,
     bold?, italic?, underline?] ==
    [other.name, other.foreground?, other.intensity?,
     other.bold?, other.italic?, other.underline?]
end

#bold?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/groonga/query-log/analyzer/reporter/console.rb', line 49

def bold?
  @bold
end

#escape_sequenceObject



85
86
87
# File 'lib/groonga/query-log/analyzer/reporter/console.rb', line 85

def escape_sequence
  "\e[#{sequence.join(';')}m"
end

#foreground?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/groonga/query-log/analyzer/reporter/console.rb', line 41

def foreground?
  @foreground
end

#intensity?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/groonga/query-log/analyzer/reporter/console.rb', line 45

def intensity?
  @intensity
end

#italic?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/groonga/query-log/analyzer/reporter/console.rb', line 53

def italic?
  @italic
end

#sequenceObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/groonga/query-log/analyzer/reporter/console.rb', line 69

def sequence
  sequence = []
  if @name == "none"
  elsif @name == "reset"
    sequence << "0"
  else
    foreground_parameter = foreground? ? 3 : 4
    foreground_parameter += 6 if intensity?
    sequence << "#{foreground_parameter}#{NAMES.index(@name)}"
  end
  sequence << "1" if bold?
  sequence << "3" if italic?
  sequence << "4" if underline?
  sequence
end

#underline?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/groonga/query-log/analyzer/reporter/console.rb', line 57

def underline?
  @underline
end