Sha256: 02765b3c9e4fdcec7414b3ba581305be4f3a86b1e1c40314486af4f3768c4d5c

Contents?: true

Size: 802 Bytes

Versions: 7

Compression:

Stored size: 802 Bytes

Contents

# frozen_string_literal: true

module RSpec
  module XlsxMatchers
    # common base row based matchers
    module InRow
      attr_reader :row_index

      def in_row(row_index)
        @row_index = row_index
        self
      end

      private

      def row
        return if sheet.nil?
        return if row_index.nil?

        @row ||= find_row
      end

      def find_row
        if defined?(Axlsx::Worksheet) && sheet.is_a?(Axlsx::Worksheet)
          sheet.rows[row_index]
        elsif defined?(Roo::Excelx) && sheet.is_a?(Roo::Excelx::Sheet)
          sheet.row(row_index + 1)
        end
      end

      def row_not_found_message
        "Row #{row_index} is empty" if row_not_found?
      end

      def row_not_found?
        row.nil? || row.compact.empty?
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rspec-xlsx_matchers-0.1.6 lib/rspec/xlsx_matchers/in_row.rb
rspec-xlsx_matchers-0.1.5 lib/rspec/xlsx_matchers/in_row.rb
rspec-xlsx_matchers-0.1.4 lib/rspec/xlsx_matchers/in_row.rb
rspec-xlsx_matchers-0.1.3 lib/rspec/xlsx_matchers/in_row.rb
rspec-xlsx_matchers-0.1.2 lib/rspec/xlsx_matchers/in_row.rb
rspec-xlsx_matchers-0.1.1 lib/rspec/xlsx_matchers/in_row.rb
rspec-xlsx_matchers-0.1.0 lib/rspec/xlsx_matchers/in_row.rb