Class: RBS::Inline::Annotator::Writer
- Inherits:
-
Object
- Object
- RBS::Inline::Annotator::Writer
- Defined in:
- lib/rbs/inline/annotator/writer.rb
Overview
action:
insert_before(range, "# @rbs foo: Integer")
insert_before(range, "# @rbs bar: Integer")
expect:
# @rbs foo: Integer
# @rbs bar: Integer
def foo(foo, bar)
Defined Under Namespace
Classes: Action, InsertAfter, InsertBefore, Replace
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#before_pos ⇒ Object
Returns the value of attribute before_pos.
-
#slice ⇒ Object
readonly
Returns the value of attribute slice.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(source) ⇒ Writer
constructor
A new instance of Writer.
- #insert_after(range:, text:) ⇒ Object
- #insert_before(range:, text:) ⇒ Object
- #process ⇒ Object
- #replace(range:, text:) ⇒ Object
Constructor Details
#initialize(source) ⇒ Writer
Returns a new instance of Writer.
64 65 66 67 68 69 |
# File 'lib/rbs/inline/annotator/writer.rb', line 64 def initialize(source) @source = source @actions = [] @slice = [] @before_pos = 0 end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
61 62 63 |
# File 'lib/rbs/inline/annotator/writer.rb', line 61 def actions @actions end |
#before_pos ⇒ Object
Returns the value of attribute before_pos.
62 63 64 |
# File 'lib/rbs/inline/annotator/writer.rb', line 62 def before_pos @before_pos end |
#slice ⇒ Object (readonly)
Returns the value of attribute slice.
61 62 63 |
# File 'lib/rbs/inline/annotator/writer.rb', line 61 def slice @slice end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
61 62 63 |
# File 'lib/rbs/inline/annotator/writer.rb', line 61 def source @source end |
Instance Method Details
#insert_after(range:, text:) ⇒ Object
75 76 77 |
# File 'lib/rbs/inline/annotator/writer.rb', line 75 def insert_after(range:, text:) actions << InsertAfter.new(range:, text:) end |
#insert_before(range:, text:) ⇒ Object
71 72 73 |
# File 'lib/rbs/inline/annotator/writer.rb', line 71 def insert_before(range:, text:) actions << InsertBefore.new(range:, text:) end |
#process ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rbs/inline/annotator/writer.rb', line 83 def process actions.sort_by { |action| action.range.begin }.each do |action| action.process(self) end if before_pos < source.length slice << source[before_pos..] end slice.join end |