Class: RBeautify::BlockStart
- Defined in:
- lib/ruby-beautify/lib/ruby-beautify/block_start.rb
Instance Attribute Summary collapse
-
#after_match ⇒ Object
readonly
Returns the value of attribute after_match.
-
#block_matcher ⇒ Object
readonly
Returns the value of attribute block_matcher.
-
#line_number ⇒ Object
readonly
Returns the value of attribute line_number.
-
#match ⇒ Object
readonly
Returns the value of attribute match.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Class Method Summary collapse
Instance Method Summary collapse
- #ancestors ⇒ Object
- #end_is_implicit? ⇒ Boolean
- #end_offset ⇒ Object
- #format_content? ⇒ Boolean
- #indent_end_line? ⇒ Boolean
- #indent_size ⇒ Object
-
#initialize(block_matcher, parent, line_number, offset, match, after_match) ⇒ BlockStart
constructor
A new instance of BlockStart.
- #name ⇒ Object
- #parse_block_end(string, offset) ⇒ Object
- #parse_content? ⇒ Boolean
-
#strict_ancestor_of?(block_start) ⇒ Boolean
Returns true if strict ancestor of.
- #total_indent_size ⇒ Object
Constructor Details
#initialize(block_matcher, parent, line_number, offset, match, after_match) ⇒ BlockStart
Returns a new instance of BlockStart.
17 18 19 20 21 22 23 24 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 17 def initialize(block_matcher, parent, line_number, offset, match, after_match) @block_matcher = block_matcher @parent = parent @offset = offset @match = match @after_match = after_match @line_number = line_number end |
Instance Attribute Details
#after_match ⇒ Object (readonly)
Returns the value of attribute after_match.
5 6 7 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 5 def after_match @after_match end |
#block_matcher ⇒ Object (readonly)
Returns the value of attribute block_matcher.
5 6 7 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 5 def block_matcher @block_matcher end |
#line_number ⇒ Object (readonly)
Returns the value of attribute line_number.
5 6 7 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 5 def line_number @line_number end |
#match ⇒ Object (readonly)
Returns the value of attribute match.
5 6 7 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 5 def match @match end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
5 6 7 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 5 def offset @offset end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
5 6 7 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 5 def parent @parent end |
Class Method Details
.first_common_ancestor(first, second) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 8 def first_common_ancestor(first, second) if first.nil? || second.nil? nil else (first.ancestors & second.ancestors).last end end |
Instance Method Details
#ancestors ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 74 def ancestors if parent parent.ancestors + [self] else [self] end end |
#end_is_implicit? ⇒ Boolean
61 62 63 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 61 def end_is_implicit? block_matcher.end_is_implicit? end |
#end_offset ⇒ Object
26 27 28 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 26 def end_offset offset + match.length end |
#format_content? ⇒ Boolean
41 42 43 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 41 def format_content? block_matcher.format_content? end |
#indent_end_line? ⇒ Boolean
49 50 51 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 49 def indent_end_line? block_matcher.indent_end_line?(self) end |
#indent_size ⇒ Object
57 58 59 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 57 def indent_size block_matcher.indent_size(self) end |
#name ⇒ Object
65 66 67 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 65 def name block_matcher.name end |
#parse_block_end(string, offset) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 30 def parse_block_end(string, offset) block_end = parse_explicit_block_end(string, offset) # Handle case where end is implicit if block_end.nil? && end_is_implicit? && parent block_end = parent.parse_block_end(string, offset) end block_end end |
#parse_content? ⇒ Boolean
45 46 47 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 45 def parse_content? block_matcher.parse_content? end |
#strict_ancestor_of?(block_start) ⇒ Boolean
Returns true if strict ancestor of
70 71 72 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 70 def strict_ancestor_of?(block_start) block_start && block_start.parent && (self == block_start.parent || strict_ancestor_of?(block_start.parent)) end |
#total_indent_size ⇒ Object
53 54 55 |
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 53 def total_indent_size parent.nil? ? indent_size : parent.total_indent_size + indent_size end |