Sha256: f6f8263642517f3fc01d5715ab0e0c34921dc3affcf9077465f3cd158b596167

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

# encoding: utf-8

module Unparser
  class Emitter
    class Literal

      # Base class for dynamic literal emitters
      class Dynamic < self

      private

        # Perform dispatch
        #
        # @return [undefined]
        #
        # @api private
        #
        def dispatch
          util = self.class
          if interpolation?
            visit_parentheses(dynamic_body, util::OPEN, util::CLOSE)
          else
            delimited(children, WS)
          end
        end

        # Test for interpolation
        #
        # @return [true]
        #   if dynamic component was interpolated
        #
        # @return [false]
        #   otherwise
        #
        # @api private
        #
        def interpolation?
          children.any? { |child| child.type != :str }
        end

        # Return dynamic body
        #
        # @return [Parser::AST::Node]
        #
        # @api private
        #
        def dynamic_body
          Parser::AST::Node.new(:dyn_str_body, children)
        end

        # Dynamic string literal emitter
        class String < self

          OPEN = CLOSE = '"'.freeze
          handle :dstr

        end # String

        # Dynamic symbol literal emitter
        class Symbol < self

          OPEN = ':"'.freeze
          CLOSE = '"'.freeze

          handle :dsym

        end # Symbol

      end
    end # Literal
  end # Emitter
end # Unparser

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
unparser-0.1.7 lib/unparser/emitter/literal/dynamic.rb
unparser-0.1.6 lib/unparser/emitter/literal/dynamic.rb