Sha256: a9c5cc8f70e485607d64d0f00a5479c3ea1b312a9ec8d7ec9411fc0f4a91e8c3

Contents?: true

Size: 860 Bytes

Versions: 3

Compression:

Stored size: 860 Bytes

Contents

module Junoser
  module Display
    module Base
      attr_accessor :output

      def initialize(io_or_string)
        @input = io_or_string
        @output = $stdout
      end


      private

      def read_io_or_string
        return @read_io_or_string if @read_io_or_string

        config = if @input.respond_to?(:read)
                   @input.read
                 else
                   @input.to_s
                 end

        @read_io_or_string = remove_blank_and_comment(config)
        @read_io_or_string = unify_carriage_return(@read_io_or_string)
      end

      def remove_blank_and_comment(str)
        str.gsub! /#.*/, ''
        str.gsub! /\/\*((?!\*\/).)*\*\//m, ''
        str.gsub! /\n\s*/, "\n"
        str.strip
      end

      def unify_carriage_return(str)
        str.gsub! /\r\n?/, "\n"
        str
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
junoser-0.1.2 lib/junoser/display/base.rb
junoser-0.1.1 lib/junoser/display/base.rb
junoser-0.1.0 lib/junoser/display/base.rb