File: total.rb

package info (click to toggle)
ruby-gitlab 5.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,660 kB
  • sloc: ruby: 12,582; makefile: 7; sh: 4
file content (29 lines) | stat: -rw-r--r-- 531 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

module Gitlab
  module Headers
    # Parses total header.
    #
    # @private
    class Total
      HEADER_TOTAL = 'x-total'
      TOTAL_REGEX = /^\d+$/

      attr_accessor :total

      def initialize(headers)
        header_total = headers[HEADER_TOTAL]

        extract_total(header_total) if header_total
      end

      private

      def extract_total(header_total)
        TOTAL_REGEX.match(header_total.strip) do |match|
          @total = match[0]
        end
      end
    end
  end
end