Class: SiSU_Utils::CodeMarker

Inherits:
Object
  • Object
show all
Defined in:
lib/sisu/utils.rb

Instance Method Summary collapse

Constructor Details

#initialize(line, file, color = :red) ⇒ CodeMarker

Returns a new instance of CodeMarker.



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

def initialize(line,file,color=:red)
  @line,@file,@color=line.to_s,file,color
end

Instance Method Details

#ansi(color = nil) ⇒ Object



62
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
88
89
# File 'lib/sisu/utils.rb', line 62

def ansi(color=nil)
  @color=color ? color : @color
  c={}
  c[:on]=case @color
  when :red         then ANSI_C[:red]
  when :green       then ANSI_C[:green]
  when :yellow      then ANSI_C[:yellow]
  when :blue        then ANSI_C[:blue]
  when :fuchsia     then ANSI_C[:fuchsia]
  when :cyan        then ANSI_C[:cyan]
  when :inv_red     then ANSI_C[:inv_red]
  when :inv_green   then ANSI_C[:inv_green]
  when :inv_yellow  then ANSI_C[:inv_yellow]
  when :inv_blue    then ANSI_C[:inv_blue]
  when :inv_fuchsia then ANSI_C[:inv_fuchsia]
  when :inv_cyan    then ANSI_C[:inv_cyan]
  when :b_red       then ANSI_C[:b_red]
  when :b_green     then ANSI_C[:b_green]
  when :b_yellow    then ANSI_C[:b_yellow]
  when :b_blue      then ANSI_C[:b_blue]
  when :b_fuchsia   then ANSI_C[:b_fuchsia]
  when :b_cyan      then ANSI_C[:b_cyan]
  else                   ANSI_C[:red]
  end
  c[:off]= ANSI_C[:off]
  #ansi_color + @line.to_s + ansi_color_off + ' ' + @file.gsub(/([^\/]+$)/,"#{ansi_color}\\1#{ansi_color_off}")
  c
end

#error(v = nil, x = nil) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/sisu/utils.rb', line 165

def error(v=nil,x=nil)
  if (v.is_a?(Symbol) \
  and x.is_a?(String))
    x="\n  " + '*ERROR* ' + x
  elsif v.is_a?(String)
    v="\n  " + '*ERROR* ' + v
    x=nil
  else
    v,x='*ERROR*',nil
  end
  STDERR.puts set(v,x)
end

#mark(v = nil, x = nil) ⇒ Object



132
133
134
# File 'lib/sisu/utils.rb', line 132

def mark(v=nil,x=nil)
  puts set(v,x)
end

#message(msg = '') ⇒ Object



119
120
121
122
123
# File 'lib/sisu/utils.rb', line 119

def message(msg='')
  @message=(msg.nil? || msg.empty?) \
  ? ''
  : ' ' + msg
end

#ok(v = nil, x = nil) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/sisu/utils.rb', line 141

def ok(v=nil,x=nil)
  if (v.is_a?(Symbol) \
  and x.is_a?(String))
    x= '*OK* ' + x
  elsif v.is_a?(String)
    v='*OK* ' + v
    x=nil
  else
    v,x='*OK*',nil
  end
  puts set(v,x)
end

#report(v = nil, x = nil) ⇒ Object



138
139
140
# File 'lib/sisu/utils.rb', line 138

def report(v=nil,x=nil)
  puts set(v,x)
end

#set(v = nil, x = nil) ⇒ Object



124
125
126
127
128
129
130
131
# File 'lib/sisu/utils.rb', line 124

def set(v=nil,x=nil)
  v=var(v,x)
  file,path=File.basename(@file),File.dirname(@file)
  v[:c][:on] + @line + v[:c][:off] + ' ' \
  + path + '/' \
  + "#{v[:c][:on]}#{file}#{v[:c][:off]}" \
  + v[:m]
end

#tell(v = nil, x = nil) ⇒ Object



135
136
137
# File 'lib/sisu/utils.rb', line 135

def tell(v=nil,x=nil)
  puts set(v,x)
end

#var(v, x) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/sisu/utils.rb', line 90

def var(v,x)
  h={ c: nil, m: '' }
  if v.is_a?(Hash)
    h[:c] = (defined? v[:c]) ? v[:c] : ''
    h[:m] = (defined? v[:m]) ? v[:m] : ''
  elsif (v.is_a?(Symbol) \
  and x.is_a?(String))
    if v.is_a?(Symbol)
      h[:c]=v
    elsif v.is_a?(String)
      h[:m]=v
    end
    if x.is_a?(String)
      h[:m]=x
    end
  elsif (v.is_a?(Symbol) \
  or v.is_a?(String))
    if v.is_a?(Symbol)
      h[:c]=v
    elsif v.is_a?(String)
      h[:m]=v
    end
  end
  h[:c] = (defined? h[:c]) ? h[:c] : ''
  h[:m] = (defined? h[:m]) ? h[:m] : ''
  h[:c]=ansi(h[:c])
  h[:m]=message(h[:m])
  h
end

#warn(v = nil, x = nil) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/sisu/utils.rb', line 153

def warn(v=nil,x=nil)
  if (v.is_a?(Symbol) \
  and x.is_a?(String))
    x="\n  " + '*WARN* ' + x
  elsif v.is_a?(String)
    v="\n  " + '*WARN* ' + v
    x=nil
  else
    v,x='*WARN*',nil
  end
  puts set(v,x)
end