Sha256: a116dcc0cbdbe8516e1cf519380575acc6e94c819d8608c460f38e1157581120

Contents?: true

Size: 961 Bytes

Versions: 10

Compression:

Stored size: 961 Bytes

Contents

module GraphQL
  module Language
    module Comments
      extend self

      def commentize(description, indent: '')
        lines = description.split("\n")

        comment = ''

        lines.each do |line|
          if line == ''
            comment << "#{indent}#\n"
          else
            sublines = break_line(line, 120 - indent.length)
            sublines.each do |subline|
              comment << "#{indent}# #{subline}\n"
            end
          end
        end

        comment
      end

      private

      def break_line(line, length)
        return [line] if line.length < length + 5

        parts = line.split(Regexp.new("((?: |^).{15,#{length - 40}}(?= |$))"))
        return [line] if parts.length < 4

        sublines = [parts.slice!(0, 3).join]

        parts.each_with_index do |part, i|
          next if i % 2 == 1
          sublines << "#{part[1..-1]}#{parts[i + 1]}"
        end

        sublines
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
graphql-1.2.6 lib/graphql/language/comments.rb
graphql-1.2.5 lib/graphql/language/comments.rb
graphql-1.2.4 lib/graphql/language/comments.rb
graphql-1.2.3 lib/graphql/language/comments.rb
graphql-1.2.2 lib/graphql/language/comments.rb
graphql-1.2.1 lib/graphql/language/comments.rb
graphql-1.2.0 lib/graphql/language/comments.rb
graphql-1.1.0 lib/graphql/language/comments.rb
graphql-1.0.0 lib/graphql/language/comments.rb
graphql-0.19.4 lib/graphql/language/comments.rb