Class: Accessionable::Base::Tag

Inherits:
Object
  • Object
show all
Defined in:
app/models/accessionable/base.rb

Direct Known Subclasses

ArrayExpressTag, EgaTag

Defined Under Namespace

Classes: FieldCollectionDate, FieldCountryOfOrigin, FieldSerializer

Constant Summary collapse

SERIALIZERS =
[FieldCountryOfOrigin.new, FieldCollectionDate.new, FieldSerializer.new].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label_scope, name, value, downcase = false) ⇒ Tag

Returns a new instance of Tag.



162
163
164
165
166
# File 'app/models/accessionable/base.rb', line 162

def initialize(label_scope, name, value, downcase = false)
  @name = name
  @value = field_serializer_for(name).value_for(downcase && value ? value.downcase : value)
  @scope = label_scope
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



72
73
74
# File 'app/models/accessionable/base.rb', line 72

def value
  @value
end

Instance Method Details

#build(xml) ⇒ Object



183
184
185
186
# File 'app/models/accessionable/base.rb', line 183

def build(xml)
  xml.TAG label
  xml.VALUE value
end

#field_serializer_for(name) ⇒ Object



179
180
181
# File 'app/models/accessionable/base.rb', line 179

def field_serializer_for(name)
  SERIALIZERS.detect { |s| s.applies_to?(name) }
end

#labelObject



168
169
170
171
172
173
174
175
176
177
# File 'app/models/accessionable/base.rb', line 168

def label
  accessioning_tag = I18n.exists?("#{@scope}.#{@name}.accessioning_tag")

  # check for field override for when ebi name is different from sanger name
  # NB. replace any underscores with spaces and ensure in lowercase
  return I18n.t("#{@scope}.#{@name}.accessioning_tag").tr('_', ' ').downcase if accessioning_tag

  # For the rest the ebi name is the same as the sanger name
  I18n.t("#{@scope}.#{@name}.label").tr('_', ' ').downcase
end