Class: Match

Inherits:
Struct show all
Defined in:
lib/selecta.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#choiceObject

Returns the value of attribute choice

Returns:

  • (Object)

    the current value of choice



371
372
373
# File 'lib/selecta.rb', line 371

def choice
  @choice
end

#matching_rangeObject

Returns the value of attribute matching_range

Returns:

  • (Object)

    the current value of matching_range



371
372
373
# File 'lib/selecta.rb', line 371

def matching_range
  @matching_range
end

#original_choiceObject

Returns the value of attribute original_choice

Returns:

  • (Object)

    the current value of original_choice



371
372
373
# File 'lib/selecta.rb', line 371

def original_choice
  @original_choice
end

#scoreObject

Returns the value of attribute score

Returns:

  • (Object)

    the current value of score



371
372
373
# File 'lib/selecta.rb', line 371

def score
  @score
end

Class Method Details

.trivial(choice) ⇒ Object



372
373
374
375
# File 'lib/selecta.rb', line 372

def self.trivial(choice)
  empty_range = (0...0)
  new(choice, choice.downcase, 0, empty_range)
end

Instance Method Details

#refine(score, range) ⇒ Object



388
389
390
# File 'lib/selecta.rb', line 388

def refine(score, range)
  Match.new(original_choice, choice, score, range)
end

#to_textObject



377
378
379
380
381
382
383
384
385
386
# File 'lib/selecta.rb', line 377

def to_text
  if matching_range.none?
    Text[original_choice]
  else
    before = original_choice[0...matching_range.begin]
    matching = original_choice[matching_range.begin..matching_range.end]
    after = original_choice[(matching_range.end + 1)..-1]
    Text[before, :red, matching, :default, after]
  end
end