Class: HtmlToHaml::Erb::IndentationTracker
- Inherits:
-
Object
- Object
- HtmlToHaml::Erb::IndentationTracker
- Defined in:
- lib/html_to_haml/tools/erb/indentation_tracker.rb
Instance Attribute Summary collapse
-
#case_statement_level ⇒ Object
readonly
Returns the value of attribute case_statement_level.
-
#indentation_amount ⇒ Object
readonly
Returns the value of attribute indentation_amount.
-
#indentation_level ⇒ Object
Returns the value of attribute indentation_level.
Instance Method Summary collapse
- #add_indentation ⇒ Object
- #begin_case_statement ⇒ Object
- #end_block ⇒ Object
-
#initialize(indentation_level:, indentation_amount:) ⇒ IndentationTracker
constructor
A new instance of IndentationTracker.
-
#nested_case_statement? ⇒ Boolean
I may allow people to use this for nested case statements, but reserve the right to be snarky about it when they do.
Constructor Details
#initialize(indentation_level:, indentation_amount:) ⇒ IndentationTracker
6 7 8 9 10 |
# File 'lib/html_to_haml/tools/erb/indentation_tracker.rb', line 6 def initialize(indentation_level:, indentation_amount:) @indentation_level = indentation_level @indentation_amount = indentation_amount @case_statement_level = [] end |
Instance Attribute Details
#case_statement_level ⇒ Object (readonly)
Returns the value of attribute case_statement_level.
5 6 7 |
# File 'lib/html_to_haml/tools/erb/indentation_tracker.rb', line 5 def case_statement_level @case_statement_level end |
#indentation_amount ⇒ Object (readonly)
Returns the value of attribute indentation_amount.
5 6 7 |
# File 'lib/html_to_haml/tools/erb/indentation_tracker.rb', line 5 def indentation_amount @indentation_amount end |
#indentation_level ⇒ Object
Returns the value of attribute indentation_level.
4 5 6 |
# File 'lib/html_to_haml/tools/erb/indentation_tracker.rb', line 4 def indentation_level @indentation_level end |
Instance Method Details
#add_indentation ⇒ Object
17 18 19 |
# File 'lib/html_to_haml/tools/erb/indentation_tracker.rb', line 17 def add_indentation self.indentation_level += indentation_amount end |
#begin_case_statement ⇒ Object
12 13 14 15 |
# File 'lib/html_to_haml/tools/erb/indentation_tracker.rb', line 12 def begin_case_statement self.indentation_level += indentation_amount * 2 case_statement_level << indentation_level end |
#end_block ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/html_to_haml/tools/erb/indentation_tracker.rb', line 21 def end_block if indentation_level == @case_statement_level.last case_statement_level.pop self.indentation_level -= indentation_amount * 2 else self.indentation_level -= indentation_amount end end |
#nested_case_statement? ⇒ Boolean
I may allow people to use this for nested case statements, but reserve the right to be snarky about it when they do.
32 33 34 |
# File 'lib/html_to_haml/tools/erb/indentation_tracker.rb', line 32 def nested_case_statement? case_statement_level.length > 1 end |