Class: Spoom::Source::Insert
Instance Attribute Summary collapse
-
#position ⇒ Object
readonly
: Integer.
-
#text ⇒ Object
readonly
: String.
Instance Method Summary collapse
-
#apply(bytes) ⇒ Object
: (Array) -> void.
-
#initialize(position, text) ⇒ Insert
constructor
: (Integer, String) -> void.
-
#range ⇒ Object
: -> [Integer, Integer].
-
#to_s ⇒ Object
: -> String.
Constructor Details
#initialize(position, text) ⇒ Insert
: (Integer, String) -> void
47 48 49 50 51 52 |
# File 'lib/spoom/source/rewriter.rb', line 47 def initialize(position, text) super() @position = position @text = text end |
Instance Attribute Details
#position ⇒ Object (readonly)
: Integer
41 42 43 |
# File 'lib/spoom/source/rewriter.rb', line 41 def position @position end |
#text ⇒ Object (readonly)
: String
44 45 46 |
# File 'lib/spoom/source/rewriter.rb', line 44 def text @text end |
Instance Method Details
#apply(bytes) ⇒ Object
: (Array) -> void
56 57 58 59 60 61 |
# File 'lib/spoom/source/rewriter.rb', line 56 def apply(bytes) raise PositionError, "Position is out of bounds" if position < 0 || position > bytes.size bytes #: untyped .insert(position, *text.bytes) end |
#range ⇒ Object
: -> [Integer, Integer]
65 66 67 |
# File 'lib/spoom/source/rewriter.rb', line 65 def range [position, position] end |
#to_s ⇒ Object
: -> String
71 72 73 |
# File 'lib/spoom/source/rewriter.rb', line 71 def to_s "Insert `#{text}` at #{position}" end |