Sha256: 184760197079ed4ae7fdd4ca6ec572bb81ea4c4cac255f8059ae7c68ae552dd9

Contents?: true

Size: 1.4 KB

Versions: 6

Compression:

Stored size: 1.4 KB

Contents

module Unparser
  class Emitter
    # Emitter if nodes
    class If < self

      handle :if

      children :condition, :if_branch, :else_branch

    private

      # Perform dispatch
      #
      # @return [undefined]
      #
      # @api private
      #
      def dispatch
        write(keyword, WS)
        emit_condition
        emit_if_branch
        emit_else_branch
        k_end
      end

      # Test for unless
      #
      # @return [true]
      #   if to emit as unless
      #
      # @return [false]
      #   otherwise
      #
      # @api private
      #
      def unless?
        !if_branch
      end

      # Return keyword
      #
      # @return [String]
      #
      # @api private
      #
      def keyword
        unless? ? K_UNLESS : K_IF
      end

      # Emit condition
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_condition
        visit(condition)
      end

      # Emit if branch
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_if_branch
        return unless if_branch
        indented { visit(if_branch) }
      end

      # Emit else branch
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_else_branch
        return unless else_branch
        write(K_ELSE) unless unless?
        indented { visit(else_branch) }
      end

    end # If
  end # Emitter
end # Unparser

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
unparser-0.0.6 lib/unparser/emitter/if.rb
unparser-0.0.5 lib/unparser/emitter/if.rb
unparser-0.0.4 lib/unparser/emitter/if.rb
unparser-0.0.3 lib/unparser/emitter/if.rb
unparser-0.0.2 lib/unparser/emitter/if.rb
unparser-0.0.1 lib/unparser/emitter/if.rb