Class: Prism::Merge::NodeBodyLayout
- Inherits:
-
Object
- Object
- Prism::Merge::NodeBodyLayout
- Defined in:
- lib/prism/merge/node_body_layout.rb
Instance Attribute Summary collapse
-
#analysis ⇒ Object
readonly
Returns the value of attribute analysis.
-
#merger ⇒ Object
readonly
Returns the value of attribute merger.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
- #body_ends_on_closing_line? ⇒ Boolean
- #body_starts_on_opening_line? ⇒ Boolean
- #body_text ⇒ Object
- #closing_line_text ⇒ Object
-
#initialize(node:, analysis:, merger:) ⇒ NodeBodyLayout
constructor
A new instance of NodeBodyLayout.
- #opening_line_text ⇒ Object
- #source_line_for_body_line(body_line) ⇒ Object
Constructor Details
#initialize(node:, analysis:, merger:) ⇒ NodeBodyLayout
Returns a new instance of NodeBodyLayout.
8 9 10 11 12 |
# File 'lib/prism/merge/node_body_layout.rb', line 8 def initialize(node:, analysis:, merger:) @node = node @analysis = analysis @merger = merger end |
Instance Attribute Details
#analysis ⇒ Object (readonly)
Returns the value of attribute analysis.
6 7 8 |
# File 'lib/prism/merge/node_body_layout.rb', line 6 def analysis @analysis end |
#merger ⇒ Object (readonly)
Returns the value of attribute merger.
6 7 8 |
# File 'lib/prism/merge/node_body_layout.rb', line 6 def merger @merger end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
6 7 8 |
# File 'lib/prism/merge/node_body_layout.rb', line 6 def node @node end |
Instance Method Details
#body_ends_on_closing_line? ⇒ Boolean
47 48 49 |
# File 'lib/prism/merge/node_body_layout.rb', line 47 def body_ends_on_closing_line? body_present? && body_statements.last.location.end_line == node.location.end_line end |
#body_starts_on_opening_line? ⇒ Boolean
43 44 45 |
# File 'lib/prism/merge/node_body_layout.rb', line 43 def body_starts_on_opening_line? body_present? && body_statements.first.location.start_line == node.location.start_line end |
#body_text ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/prism/merge/node_body_layout.rb', line 14 def body_text return '' unless body_present? lines = [] lines << opening_line_body_text if body_starts_on_opening_line? middle_body_line_range.each do |line_num| lines << analysis.line_at(line_num).to_s.chomp end lines << closing_line_body_text if body_ends_on_closing_line? return '' if lines.empty? "#{lines.join("\n")}\n" end |
#closing_line_text ⇒ Object
37 38 39 40 41 |
# File 'lib/prism/merge/node_body_layout.rb', line 37 def closing_line_text return analysis.line_at(node.location.end_line).to_s.chomp unless body_ends_on_closing_line? analysis.source.byteslice(body_end_offset...line_end_offset(node.location.end_line)).to_s.chomp end |
#opening_line_text ⇒ Object
31 32 33 34 35 |
# File 'lib/prism/merge/node_body_layout.rb', line 31 def opening_line_text return analysis.line_at(node.location.start_line).to_s.chomp unless body_starts_on_opening_line? analysis.source.byteslice(line_start_offset(node.location.start_line)...body_start_offset).to_s end |
#source_line_for_body_line(body_line) ⇒ Object
51 52 53 54 55 |
# File 'lib/prism/merge/node_body_layout.rb', line 51 def source_line_for_body_line(body_line) return unless body_line body_source_lines[body_line - 1] end |