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.



167
168
169
170
171
# File 'app/models/accessionable/base.rb', line 167

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.



81
82
83
# File 'app/models/accessionable/base.rb', line 81

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



173
174
175
176
177
# File 'app/models/accessionable/base.rb', line 173

def label
  accessioning_tag = I18n.exists?("#{@scope}.#{@name}.accessioning_tag")
  return I18n.t("#{@scope}.#{@name}.accessioning_tag").tr(' ', '_').downcase if accessioning_tag
  I18n.t("#{@scope}.#{@name}.label").tr(' ', '_').downcase
end