Class: Spoom::Source::Replace
Instance Attribute Summary collapse
- #from ⇒ Object readonly
- #text ⇒ Object readonly
- #to ⇒ Object readonly
Instance Method Summary collapse
- #apply(bytes) ⇒ Object
-
#initialize(from, to, text) ⇒ Replace
constructor
A new instance of Replace.
- #range ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(from, to, text) ⇒ Replace
Returns a new instance of Replace.
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)
78 79 80 |
# File 'lib/spoom/source/rewriter.rb', line 78 def from @from end |
#text ⇒ Object (readonly)
81 82 83 |
# File 'lib/spoom/source/rewriter.rb', line 81 def text @text end |
#to ⇒ Object (readonly)
78 79 80 |
# File 'lib/spoom/source/rewriter.rb', line 78 def to @to end |
Instance Method Details
#apply(bytes) ⇒ Object
94 95 96 97 98 99 |
# 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
103 104 105 |
# File 'lib/spoom/source/rewriter.rb', line 103 def range [from, to] end |
#to_s ⇒ Object
109 110 111 |
# File 'lib/spoom/source/rewriter.rb', line 109 def to_s "Replace #{from}-#{to} with `#{text}`" end |