Sha256: ebacc452a21285320e12c59b70d0052654585e1d257dcbc96b39c12330f5a112

Contents?: true

Size: 574 Bytes

Versions: 1

Compression:

Stored size: 574 Bytes

Contents

module SearchKit
  module Models
    class Document
      class AttributeNotFound < StandardError; end

      include Virtus.model

      attribute :id
      attribute :source
      attribute :score

      def initialize(document_data = {})
        super(
          source: document_data.fetch(:source, {}),
          id:     document_data.fetch(:id, nil),
          score:  document_data.fetch(:score, nil)
        )
      end

      def get(field)
        source.fetch(field.to_sym)
      rescue KeyError
        fail AttributeNotFound, field
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
search-kit-0.0.7 lib/search_kit/models/document.rb