Class: HintableLevenshtein::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/hintable_levenshtein/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, chr = nil) ⇒ Event

Returns a new instance of Event.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/hintable_levenshtein/event.rb', line 6

def initialize(type, chr = nil)
  @type = type
  case type
  when :substitute
    unless chr.nil?
      @from = chr.keys.first
      @from = @from.chr unless @from.is_a?(String)
      @to = chr.values.first
      @to = @to.chr unless @to.is_a?(String)
    else
      @from = @to = nil
    end
  else
    @chr = chr.is_a?(String) ? chr : chr.chr
  end
end

Instance Attribute Details

#chrObject (readonly)

Returns the value of attribute chr.



4
5
6
# File 'lib/hintable_levenshtein/event.rb', line 4

def chr
  @chr
end

#fromObject (readonly)

Returns the value of attribute from.



4
5
6
# File 'lib/hintable_levenshtein/event.rb', line 4

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



4
5
6
# File 'lib/hintable_levenshtein/event.rb', line 4

def to
  @to
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/hintable_levenshtein/event.rb', line 4

def type
  @type
end

Instance Method Details

#to_sObject



23
24
25
26
27
28
29
# File 'lib/hintable_levenshtein/event.rb', line 23

def to_s
  if from
    "#{type} -> #{from}..#{to}"
  else
    "#{type} -> #{chr}"
  end
end