Class: Dratools::TraversalNode

Inherits:
Object
  • Object
show all
Defined in:
lib/dratools/traversal_node.rb

Overview

DDBJ record traversal and download leaves for tree rendering.

Constant Summary collapse

ROOT_RELATION =
:root
DB_XREF_RELATION =
:db_xref
CHILD_BIOPROJECT_RELATION =
:child_bioproject
DOWNLOAD_RELATION =
:download

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relation: ROOT_RELATION, type: nil, accession: nil, object_type: nil, record: nil, url: nil, error: nil, children: [], download: nil) ⇒ TraversalNode

rubocop:disable Metrics/ParameterLists



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dratools/traversal_node.rb', line 14

def initialize( # rubocop:disable Metrics/ParameterLists
  relation: ROOT_RELATION,
  type: nil,
  accession: nil,
  object_type: nil,
  record: nil,
  url: nil,
  error: nil,
  children: [],
  download: nil
)
  @relation = relation
  @type = type
  @accession = accession
  @object_type = object_type
  @record = record
  @url = url
  @error = error
  @children = children
  @download = download
end

Instance Attribute Details

#accessionObject (readonly)

Returns the value of attribute accession.



11
12
13
# File 'lib/dratools/traversal_node.rb', line 11

def accession
  @accession
end

#childrenObject (readonly)

Returns the value of attribute children.



11
12
13
# File 'lib/dratools/traversal_node.rb', line 11

def children
  @children
end

#downloadObject (readonly)

Returns the value of attribute download.



11
12
13
# File 'lib/dratools/traversal_node.rb', line 11

def download
  @download
end

#errorObject (readonly)

Returns the value of attribute error.



11
12
13
# File 'lib/dratools/traversal_node.rb', line 11

def error
  @error
end

#object_typeObject (readonly)

Returns the value of attribute object_type.



11
12
13
# File 'lib/dratools/traversal_node.rb', line 11

def object_type
  @object_type
end

#recordObject (readonly)

Returns the value of attribute record.



11
12
13
# File 'lib/dratools/traversal_node.rb', line 11

def record
  @record
end

#relationObject (readonly)

Returns the value of attribute relation.



11
12
13
# File 'lib/dratools/traversal_node.rb', line 11

def relation
  @relation
end

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/dratools/traversal_node.rb', line 11

def type
  @type
end

#urlObject (readonly)

Returns the value of attribute url.



11
12
13
# File 'lib/dratools/traversal_node.rb', line 11

def url
  @url
end

Instance Method Details

#download?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/dratools/traversal_node.rb', line 40

def download?
  relation == DOWNLOAD_RELATION
end

#downloadsObject



58
59
60
61
# File 'lib/dratools/traversal_node.rb', line 58

def downloads
  own_downloads = download ? [download] : []
  own_downloads + children.flat_map(&:downloads)
end

#errored?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/dratools/traversal_node.rb', line 44

def errored?
  !error.to_s.empty?
end

#errorsObject



63
64
65
66
# File 'lib/dratools/traversal_node.rb', line 63

def errors
  own_errors = errored? ? [error] : []
  own_errors + children.flat_map(&:errors)
end

#run?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/dratools/traversal_node.rb', line 36

def run?
  type == DdbjRecordFields::SRA_RUN_RESOURCE_TYPE
end

#run_accessionsObject



53
54
55
56
# File 'lib/dratools/traversal_node.rb', line 53

def run_accessions
  accessions = run? && accession ? [accession] : []
  accessions + children.reject(&:download?).flat_map(&:run_accessions)
end

#run_recordsObject



48
49
50
51
# File 'lib/dratools/traversal_node.rb', line 48

def run_records
  records = run? && record ? [record] : []
  records + children.flat_map(&:run_records)
end