Class: Ibex::Runtime::RepairEdit

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/runtime/repair.rb

Overview

One immutable insertion, deletion, or replacement.

Constant Summary collapse

KINDS =

: Array

%i[insert delete replace].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind:, position:, token_id:, token_name:, cost:) ⇒ RepairEdit

Returns a new instance of RepairEdit.

Raises:

  • (ArgumentError)


52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ibex/runtime/repair.rb', line 52

def initialize(kind:, position:, token_id:, token_name:, cost:)
  raise ArgumentError, "unknown repair edit #{kind.inspect}" unless KINDS.include?(kind)
  raise ArgumentError, "repair edit position must be nonnegative" if position.negative?
  raise ArgumentError, "repair edit cost must be positive" unless cost.positive?

  @kind = kind
  @position = position
  @token_id = token_id
  @token_name = token_name.dup.freeze
  @cost = cost
  freeze
end

Instance Attribute Details

#costObject (readonly)

: Integer



49
50
51
# File 'lib/ibex/runtime/repair.rb', line 49

def cost
  @cost
end

#kindObject (readonly)

: Symbol



45
46
47
# File 'lib/ibex/runtime/repair.rb', line 45

def kind
  @kind
end

#positionObject (readonly)

: Integer



46
47
48
# File 'lib/ibex/runtime/repair.rb', line 46

def position
  @position
end

#token_idObject (readonly)

: Integer



47
48
49
# File 'lib/ibex/runtime/repair.rb', line 47

def token_id
  @token_id
end

#token_nameObject (readonly)

: String



48
49
50
# File 'lib/ibex/runtime/repair.rb', line 48

def token_name
  @token_name
end

Instance Method Details

#to_hObject



66
67
68
# File 'lib/ibex/runtime/repair.rb', line 66

def to_h
  { kind: @kind, position: @position, token_id: @token_id, token_name: @token_name, cost: @cost }.freeze
end