Class: Accession::TagList
- Inherits:
-
Object
- Object
- Accession::TagList
- 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
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#missing ⇒ Object
readonly
Returns the value of attribute missing.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #add(tag) ⇒ Object (also: #<<)
- #array_express_labels ⇒ Object
-
#by_group ⇒ Object
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.
- #each ⇒ Object
-
#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.
- #find(key) ⇒ Object
-
#initialize(tags = {}) {|_self| ... } ⇒ TagList
constructor
A new instance of TagList.
- #labels ⇒ Object
-
#meets_service_requirements?(service, standard_tags) ⇒ Boolean
Check that the tag list meets the requirements for accessioning for a particular service i.e.
- #required_for(service) ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(tags = {}) {|_self| ... } ⇒ TagList
Returns a new instance of TagList.
20 21 22 23 24 25 |
# File 'lib/accession/accession/tag_list.rb', line 20 def initialize( = {}) @tags = {} (.with_indifferent_access) @groups = self..values.collect(&:groups).flatten.uniq yield self if block_given? end |
Instance Attribute Details
#groups ⇒ Object
Returns the value of attribute groups.
16 17 18 |
# File 'lib/accession/accession/tag_list.rb', line 16 def groups @groups end |
#missing ⇒ Object (readonly)
Returns the value of attribute missing.
15 16 17 |
# File 'lib/accession/accession/tag_list.rb', line 15 def missing @missing end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
15 16 17 |
# File 'lib/accession/accession/tag_list.rb', line 15 def @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) <=> other. end |
#add(tag) ⇒ Object Also known as: <<
60 61 62 |
# File 'lib/accession/accession/tag_list.rb', line 60 def add(tag) [tag.name] = tag end |
#array_express_labels ⇒ Object
56 57 58 |
# File 'lib/accession/accession/tag_list.rb', line 56 def array_express_labels .values.collect(&:array_express_label) end |
#by_group ⇒ Object
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| .values.each { |tag| tag.groups.each { |group| result[group] << tag } } } end |
#each ⇒ Object
27 28 29 |
# File 'lib/accession/accession/tag_list.rb', line 27 def each(&) .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| .keys.each do |key| value = [key].value_for(record, key) tag_list.add([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) [key.to_s] end |
#labels ⇒ Object
48 49 50 |
# File 'lib/accession/accession/tag_list.rb', line 48 def labels .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.
79 80 81 82 |
# File 'lib/accession/accession/tag_list.rb', line 79 def meets_service_requirements?(service, ) @missing = .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) .select { |_k, tag| tag.required_for?(service) } end |
#values ⇒ Object
52 53 54 |
# File 'lib/accession/accession/tag_list.rb', line 52 def values .values.collect(&:value) end |