Sha256: 4a2d0ad9dee368810408483e5edc05c4a99b1f776bac7dd8ba5f7a71d24f3ec1

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

#
# Copyright (c) 2019-present, Blue Marble Payroll, LLC
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#

module Airspace
  # Metdata is 'data about a dataset.'  These are key pieces of information we need to store with
  # the data then later retrieve with the data.
  class Metadata
    DEFAULT_PAGES_PER_CHUNK = 5

    attr_reader :expires_in_seconds,
                :page_count,
                :pages_per_chunk

    def initialize(expires_in_seconds: nil, page_count: 0, pages_per_chunk: DEFAULT_PAGES_PER_CHUNK)
      @expires_in_seconds = expires_in_seconds ? expires_in_seconds.to_i : nil
      @page_count         = page_count.to_i
      @pages_per_chunk    = pages_per_chunk ? pages_per_chunk.to_i : DEFAULT_PAGES_PER_CHUNK

      freeze
    end

    def chunker
      ::Airspace::Chunker.new(pages_per_chunk)
    end

    def chunk_count
      chunker.count(page_count)
    end

    def to_json
      {
        expires_in_seconds: expires_in_seconds,
        page_count: page_count,
        pages_per_chunk: pages_per_chunk
      }.to_json
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
airspace-1.0.1 lib/airspace/metadata.rb
airspace-1.0.0 lib/airspace/metadata.rb