gogotanaka/Hilbert

View on GitHub
lib/hilbert/parser/matrix_parser.rb

Summary

Maintainability
A
0 mins
Test Coverage
module Hilbert
  module Parser
    module MatrixParser
      include Base
      def execute(els, opts = { trans: false })
        trans = opts[:trans]
        rows = els.first.split(/ *(?:;|\n) */).map(&:split_by_sp)
        rows.all? { |row| row.count == rows.first.count }
        if trans
          rows = rows.transpose
        end
        MatrixApi.execute(rows)
      end
      module_function :execute
    end
  end
end