Class: ComplyanceSDK::Models::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/complyance_sdk/models/source.rb

Overview

Source model representing the origin of documents

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Source

Initialize a new source

Parameters:

  • options (Hash) (defaults to: {})

    Source options

Options Hash (options):

  • :id (String)

    Source ID

  • :type (Symbol, String)

    Source type

  • :name (String)

    Source name

  • :version (String)

    Source version

  • :metadata (Hash)

    Source metadata



49
50
51
52
53
54
55
# File 'lib/complyance_sdk/models/source.rb', line 49

def initialize(options = {})
  @id = options[:id]
  @type = parse_source_type(options[:type])
  @name = options[:name]
  @version = options[:version]
  @metadata = options[:metadata] || {}
end

Instance Attribute Details

#idObject

Source ID



27
28
29
# File 'lib/complyance_sdk/models/source.rb', line 27

def id
  @id
end

#metadataObject

Source metadata



39
40
41
# File 'lib/complyance_sdk/models/source.rb', line 39

def 
  @metadata
end

#nameObject

Source name



33
34
35
# File 'lib/complyance_sdk/models/source.rb', line 33

def name
  @name
end

#typeObject

Source type



30
31
32
# File 'lib/complyance_sdk/models/source.rb', line 30

def type
  @type
end

#versionObject

Source version



36
37
38
# File 'lib/complyance_sdk/models/source.rb', line 36

def version
  @version
end

Instance Method Details

#to_hHash

Convert the source to a hash

Returns:

  • (Hash)

    The source as a hash



60
61
62
63
64
65
66
67
68
# File 'lib/complyance_sdk/models/source.rb', line 60

def to_h
  {
    name: @name,
    version: @version,
    type: @type.to_s.upcase,
    identity: "#{@name}:#{@version}",
    id: "#{@name}:#{@version}"
  }
end

#to_json(*args) ⇒ String

Convert the source to JSON

Returns:

  • (String)

    The source as JSON



73
74
75
# File 'lib/complyance_sdk/models/source.rb', line 73

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

#valid?Boolean

Check if the source is valid

Returns:

  • (Boolean)

    True if valid, false otherwise



80
81
82
83
84
# File 'lib/complyance_sdk/models/source.rb', line 80

def valid?
  !@id.nil? && !@id.empty? &&
    !@name.nil? && !@name.empty? &&
    SourceType.all.include?(@type)
end