Class: Lisp::Format::Directives::EndCaseConversion

Inherits:
Directive show all
Defined in:
lib/carat/lisp-format.rb

Overview

Represents the ~) (End case-conversion) directive. Everything contained within it and its matching pair ~( (Begin case-conversion) directive is subject to case conversion, such as upcasing or capitalization.

Instance Attribute Summary

Attributes inherited from Directive

#pos

Instance Method Summary collapse

Methods inherited from Directive

#initialize, #join

Constructor Details

This class inherits a constructor from Lisp::Format::Directives::Directive

Instance Method Details

#execute(state) ⇒ Object

This does the actual work for the ~( directive, in that it collects all the output between its matching directive (~() and outputs it using one of the conversions set up by the ~( (BeginCaseConversion) directive.



1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
# File 'lib/carat/lisp-format.rb', line 1469

def execute(state)
  output = state.pop_output.to_s
  state.output(
              case state.case_conv
              when :DOWN
                output.downcase
              when :CAP
                output.gsub(/\w+/) do |w| w.capitalize end
              when :CAP_FIRST
                output.capitalize
              when :UP
                output.upcase
              end
              )
end