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:


17
18
19
20
21
22
# File 'lib/accession/accession/tag_list.rb', line 17

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


13
14
15
# File 'lib/accession/accession/tag_list.rb', line 13

def groups
  @groups
end

#missingObject (readonly)

Returns the value of attribute missing


12
13
14
# File 'lib/accession/accession/tag_list.rb', line 12

def missing
  @missing
end

#tagsObject (readonly)

Returns the value of attribute tags


12
13
14
# File 'lib/accession/accession/tag_list.rb', line 12

def tags
  @tags
end

Instance Method Details

#<=>(other) ⇒ Object


87
88
89
90
91
# File 'lib/accession/accession/tag_list.rb', line 87

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

  tags <=> other.tags
end

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


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

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

#array_express_labelsObject


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

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.


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

def by_group
  groups.each_with_object({}) { |v, h| h[v] = TagList.new }.tap do |result|
    tags.values.each do |tag|
      tag.groups.each do |group|
        result[group] << tag
      end
    end
  end
end

#each(&block) ⇒ Object


24
25
26
# File 'lib/accession/accession/tag_list.rb', line 24

def each(&block)
  tags.each(&block)
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


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

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

#find(key) ⇒ Object


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

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

#labelsObject


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

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.


82
83
84
85
# File 'lib/accession/accession/tag_list.rb', line 82

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


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

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

#valuesObject


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

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