Class: Dratools::TraversalNode
- Inherits:
-
Object
- Object
- Dratools::TraversalNode
- 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
-
#accession ⇒ Object
readonly
Returns the value of attribute accession.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#download ⇒ Object
readonly
Returns the value of attribute download.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#object_type ⇒ Object
readonly
Returns the value of attribute object_type.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#relation ⇒ Object
readonly
Returns the value of attribute relation.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #download? ⇒ Boolean
- #downloads ⇒ Object
- #errored? ⇒ Boolean
- #errors ⇒ Object
-
#initialize(relation: ROOT_RELATION, type: nil, accession: nil, object_type: nil, record: nil, url: nil, error: nil, children: [], download: nil) ⇒ TraversalNode
constructor
rubocop:disable Metrics/ParameterLists.
- #run? ⇒ Boolean
- #run_accessions ⇒ Object
- #run_records ⇒ Object
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
#accession ⇒ Object (readonly)
Returns the value of attribute accession.
11 12 13 |
# File 'lib/dratools/traversal_node.rb', line 11 def accession @accession end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
11 12 13 |
# File 'lib/dratools/traversal_node.rb', line 11 def children @children end |
#download ⇒ Object (readonly)
Returns the value of attribute download.
11 12 13 |
# File 'lib/dratools/traversal_node.rb', line 11 def download @download end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
11 12 13 |
# File 'lib/dratools/traversal_node.rb', line 11 def error @error end |
#object_type ⇒ Object (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 |
#record ⇒ Object (readonly)
Returns the value of attribute record.
11 12 13 |
# File 'lib/dratools/traversal_node.rb', line 11 def record @record end |
#relation ⇒ Object (readonly)
Returns the value of attribute relation.
11 12 13 |
# File 'lib/dratools/traversal_node.rb', line 11 def relation @relation end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
11 12 13 |
# File 'lib/dratools/traversal_node.rb', line 11 def type @type end |
#url ⇒ Object (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
40 41 42 |
# File 'lib/dratools/traversal_node.rb', line 40 def download? relation == DOWNLOAD_RELATION end |
#downloads ⇒ Object
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
44 45 46 |
# File 'lib/dratools/traversal_node.rb', line 44 def errored? !error.to_s.empty? end |
#errors ⇒ Object
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
36 37 38 |
# File 'lib/dratools/traversal_node.rb', line 36 def run? type == DdbjRecordFields::SRA_RUN_RESOURCE_TYPE end |
#run_accessions ⇒ Object
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_records ⇒ Object
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 |