Class: Accession::TagList

Inherits:
Object
  • Object
show all
Includes:
Comparable, Enumerable
Defined in:
lib/accession/accession/tag_list.rb

Overview

Tags details are stored in config/accession/tags.yml Standard TagList is created on initialisation from this yaml file and can be reached through Accession.configuration.tags TagList that is specific to a particular sample can be created using #extract method (where ‘record’ is a Sequencescape Sample::Metadata object) Tags contain information about a sample, that should be provided to an external service to accession the sample Tags are used to validate a sample and to create a correct xml file for accessioning request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tags = {}) {|_self| ... } ⇒ TagList

Returns a new instance of TagList.

Yields:

  • (_self)

Yield Parameters:



20
21
22
23
24
25
# File 'lib/accession/accession/tag_list.rb', line 20

def initialize(tags = {})
  @tags = {}
  add_tags(tags.with_indifferent_access)
  @groups = self.tags.values.collect(&:groups).flatten.uniq
  yield self if block_given?
end

Instance Attribute Details

#groupsObject

Returns the value of attribute groups.



16
17
18
# File 'lib/accession/accession/tag_list.rb', line 16

def groups
  @groups
end

#missingObject (readonly)

Returns the value of attribute missing.



15
16
17
# File 'lib/accession/accession/tag_list.rb', line 15

def missing
  @missing
end

#tagsObject (readonly)

Returns the value of attribute tags.



15
16
17
# File 'lib/accession/accession/tag_list.rb', line 15

def tags
  @tags
end

Instance Method Details

#<=>(other) ⇒ Object



84
85
86
87
88
# File 'lib/accession/accession/tag_list.rb', line 84

def <=>(other)
  return unless other.is_a?(self.class)

  tags <=> other.tags
end

#add(tag) ⇒ Object Also known as: <<



60
61
62
# File 'lib/accession/accession/tag_list.rb', line 60

def add(tag)
  tags[tag.name] = tag
end

#array_express_labelsObject



56
57
58
# File 'lib/accession/accession/tag_list.rb', line 56

def array_express_labels
  tags.values.collect(&:array_express_label)
end

#by_groupObject

create a hash of tags based on the groups which will define how the xml is constructed each key will be the group and each value will be a new TagList to allow tag list methods to be called.



42
43
44
45
46
# File 'lib/accession/accession/tag_list.rb', line 42

def by_group
  groups
    .index_with { |_v| TagList.new }
    .tap { |result| tags.values.each { |tag| tag.groups.each { |group| result[group] << tag } } }
end

#eachObject



27
28
29
# File 'lib/accession/accession/tag_list.rb', line 27

def each(&)
  tags.each(&)
end

#extract(record) ⇒ Object

Extract a new TagList based on an Accession::Sample The TagList will consist of a tag for which the sample has attributes



67
68
69
70
71
72
73
74
75
# File 'lib/accession/accession/tag_list.rb', line 67

def extract(record)
  TagList.new do |tag_list|
    tags.keys.each do |key|
      value = tags[key].value_for(record, key)
      tag_list.add(tags[key].dup.add_value(value)) if value.present?
    end
    tag_list.groups = groups
  end
end

#find(key) ⇒ Object



35
36
37
# File 'lib/accession/accession/tag_list.rb', line 35

def find(key)
  tags[key.to_s]
end

#labelsObject



48
49
50
# File 'lib/accession/accession/tag_list.rb', line 48

def labels
  tags.values.collect(&:label)
end

#meets_service_requirements?(service, standard_tags) ⇒ Boolean

Check that the tag list meets the requirements for accessioning for a particular service i.e. check that it has the required tags.

Returns:

  • (Boolean)


79
80
81
82
# File 'lib/accession/accession/tag_list.rb', line 79

def meets_service_requirements?(service, standard_tags)
  @missing = standard_tags.required_for(service).keys - required_for(service).keys
  missing.empty?
end

#required_for(service) ⇒ Object



31
32
33
# File 'lib/accession/accession/tag_list.rb', line 31

def required_for(service)
  tags.select { |_k, tag| tag.required_for?(service) }
end

#valuesObject



52
53
54
# File 'lib/accession/accession/tag_list.rb', line 52

def values
  tags.values.collect(&:value)
end