Class: Spoom::Source::Replace
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
: Integer.
-
#text ⇒ Object
readonly
: String.
-
#to ⇒ Object
readonly
: Integer.
Instance Method Summary collapse
-
#apply(bytes) ⇒ Object
: (Array) -> void.
-
#initialize(from, to, text) ⇒ Replace
constructor
: (Integer, Integer, String) -> void.
-
#range ⇒ Object
: -> [Integer, Integer].
-
#to_s ⇒ Object
: -> String.
Constructor Details
#initialize(from, to, text) ⇒ Replace
: (Integer, Integer, String) -> void
84 85 86 87 88 89 90 |
# File 'lib/spoom/source/rewriter.rb', line 84 def initialize(from, to, text) super() @from = from @to = to @text = text end |
Instance Attribute Details
#from ⇒ Object (readonly)
: Integer
78 79 80 |
# File 'lib/spoom/source/rewriter.rb', line 78 def from @from end |
#text ⇒ Object (readonly)
: String
81 82 83 |
# File 'lib/spoom/source/rewriter.rb', line 81 def text @text end |
#to ⇒ Object (readonly)
: Integer
78 79 80 |
# File 'lib/spoom/source/rewriter.rb', line 78 def to @to end |
Instance Method Details
#apply(bytes) ⇒ Object
: (Array) -> void
94 95 96 97 98 |
# File 'lib/spoom/source/rewriter.rb', line 94 def apply(bytes) raise PositionError, "Position is out of bounds" if from < 0 || to < 0 || from > bytes.size || to > bytes.size || from > to bytes[from..to] = *text.bytes end |
#range ⇒ Object
: -> [Integer, Integer]
102 103 104 |
# File 'lib/spoom/source/rewriter.rb', line 102 def range [from, to] end |
#to_s ⇒ Object
: -> String
108 109 110 |
# File 'lib/spoom/source/rewriter.rb', line 108 def to_s "Replace #{from}-#{to} with `#{text}`" end |