class Shaf::ALPS::AttributeSerializer

Attributes

attribute[R]

Public Class Methods

call(arg) click to toggle source
# File lib/shaf/alps/attribute_serializer.rb, line 8
def self.call(arg)
  new(arg).to_hash
end
new(attribute) click to toggle source
# File lib/shaf/alps/attribute_serializer.rb, line 12
def initialize(attribute)
  @attribute = attribute
end

Public Instance Methods

to_hash() click to toggle source
# File lib/shaf/alps/attribute_serializer.rb, line 16
def to_hash
  {
    id: attribute.id,
    type: 'semantic',
  }.merge(optional_properties)
end

Private Instance Methods

optional_properties() click to toggle source
# File lib/shaf/alps/attribute_serializer.rb, line 25
def optional_properties
  descriptors = serialized_descriptors
  hash = {}
  hash[:href] = attribute.href if attribute.href
  hash[:doc] = { value: attribute.doc } if attribute.doc
  hash[:name] = attribute.name.to_s if attribute.name
  hash[:descriptor] = descriptors unless descriptors.empty?
  hash
end
serialized_descriptors() click to toggle source
# File lib/shaf/alps/attribute_serializer.rb, line 35
def serialized_descriptors
  descriptors = attribute.attributes.map { |attr| self.class.call(attr) }
  descriptors += attribute.relations.map { |rel| RelationSerializer.call(rel) }
end