Sha256: 50a29d9b0a380ac0cd578a811933a16b2f11541456e36f0fd9c950f2efe8f72b

Contents?: true

Size: 1.39 KB

Versions: 11

Compression:

Stored size: 1.39 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
        visit_indented(if_branch)
      end

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

    end # If
  end # Emitter
end # Unparser

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
unparser-0.1.0 lib/unparser/emitter/if.rb
unparser-0.0.18 lib/unparser/emitter/if.rb
unparser-0.0.16 lib/unparser/emitter/if.rb
unparser-0.0.15 lib/unparser/emitter/if.rb
unparser-0.0.14 lib/unparser/emitter/if.rb
unparser-0.0.13 lib/unparser/emitter/if.rb
unparser-0.0.12 lib/unparser/emitter/if.rb
unparser-0.0.11 lib/unparser/emitter/if.rb
unparser-0.0.10 lib/unparser/emitter/if.rb
unparser-0.0.8 lib/unparser/emitter/if.rb
unparser-0.0.7 lib/unparser/emitter/if.rb