<commit_before># frozen_string_literal: true

class ActivityPub::ImageSerializer < ActiveModel::Serializer
  include RoutingHelper

  attributes :type, :media_type, :url
  attribute :focal_point, if: :focal_point?

  def type
    'Image'
  end

  def url
    full_asset_url(object.url(:original))
  end

  def media_type
    object.content_type
  end

  def focal_point?
    object.respond_to?(:meta) && object.meta['focus'].is_a?(Hash)
  end

  def focal_point
    [object.meta['focus']['x'], object.meta['focus']['y']]
  end
end
<commit_msg>Fix nil error in focal_point? (#6537)<commit_after># frozen_string_literal: true

class ActivityPub::ImageSerializer < ActiveModel::Serializer
  include RoutingHelper

  attributes :type, :media_type, :url
  attribute :focal_point, if: :focal_point?

  def type
    'Image'
  end

  def url
    full_asset_url(object.url(:original))
  end

  def media_type
    object.content_type
  end

  def focal_point?
    object.respond_to?(:meta) && object.meta.is_a?(Hash) && object.meta['focus'].is_a?(Hash)
  end

  def focal_point
    [object.meta['focus']['x'], object.meta['focus']['y']]
  end
end

{'fraction_non_alphanumeric': 0.12752858399296393, 'fraction_numerical': 0.003518029903254178, 'mean_word_length': 4.367924528301887, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1879963', 'n_tokens_mistral': 403, 'n_tokens_neox': 384, 'n_words': 84}