Sha256: cf59083d8cded48c6cc7e20ed6d0f1a5a44e8d87d0af5f9d969280073d403acc

Contents?: true

Size: 1019 Bytes

Versions: 3

Compression:

Stored size: 1019 Bytes

Contents

# frozen_string_literal: true

module Sandbox
  # Anchor describes an anchor on a Sandbox Attribute
  class Anchor
    attr_reader :type
    attr_reader :value
    attr_reader :sub_type
    attr_reader :timestamp

    def initialize(type:, value:, sub_type: '', timestamp: Time.now)
      @type = type
      @value = value
      @sub_type = sub_type
      @timestamp = timestamp
    end

    def as_json(*_args)
      {
        type: @type,
        value: @value,
        sub_type: @sub_type,
        timestamp: @timestamp.to_i
      }
    end

    def to_json(*args)
      as_json.to_json(*args)
    end

    def self.source(value, sub_type: '', timestamp: Time.now)
      Anchor.new(
        type: 'SOURCE',
        value: value,
        sub_type: sub_type,
        timestamp: timestamp
      )
    end

    def self.verifier(value, sub_type: '', timestamp: Time.now)
      Anchor.new(
        type: 'VERIFIER',
        value: value,
        sub_type: sub_type,
        timestamp: timestamp
      )
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
yoti-1.6.2 lib/yoti/sandbox/anchor.rb
yoti-1.6.1 lib/yoti/sandbox/anchor.rb
yoti-1.6.0 lib/yoti/sandbox/anchor.rb