Class: Line

Inherits:
Object
  • Object
show all
Defined in:
lib/cless/data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a, onl = nil, off = nil) ⇒ Line

Returns a new instance of Line.



210
211
212
213
214
215
216
# File 'lib/cless/data.rb', line 210

def initialize(a, onl = nil, off = nil)
  @a, @onl = a, onl
  @m = []
  @has_match = false
  @off = off
  @highlight = false
end

Instance Attribute Details

#has_matchObject (readonly)

Returns the value of attribute has_match.



206
207
208
# File 'lib/cless/data.rb', line 206

def has_match
  @has_match
end

#highlightObject Also known as: highlight?

Returns the value of attribute highlight.



207
208
209
# File 'lib/cless/data.rb', line 207

def highlight
  @highlight
end

#offObject (readonly)

Returns the value of attribute off.



206
207
208
# File 'lib/cless/data.rb', line 206

def off
  @off
end

Instance Method Details

#clear_matchObject



242
# File 'lib/cless/data.rb', line 242

def clear_match; @has_match = false; @m.clear; end

#ignoredObject Also known as: ignored?



218
# File 'lib/cless/data.rb', line 218

def ignored; false; end

#match(pattern) ⇒ Object

onl is the line before any formatting or transformation. If a field doesn’t match pattern but old representation does, hilight entire field as a match.



228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/cless/data.rb', line 228

def match(pattern)
  does_match = false
  @a.each_with_index { |f, i|
    if m = f.match(pattern)
      does_match = true
      @m[i] = m
    elsif @onl && @onl[i].match(pattern)
      does_match = true
      @m[i] = FieldMatch.new(f)
    end
  }
  @has_match = does_match
end

#matches_at(*args) ⇒ Object



223
# File 'lib/cless/data.rb', line 223

def matches_at(*args); @m.values_at(*args); end

#onl_at(*args) ⇒ Object



222
# File 'lib/cless/data.rb', line 222

def onl_at(*args); (@onl || @a).values_at(*args); end

#values_at(*args) ⇒ Object



221
# File 'lib/cless/data.rb', line 221

def values_at(*args); @a.values_at(*args); end