<commit_before># frozen_string_literal: true

class TwitterAccount < ApplicationRecord
  belongs_to :user

  validates :handle, presence: true
  validates :user, uniqueness: {
    scope: :handle, case_sensitive: false, message: lambda(account, data) do
      "#{data[:value].email} is already receiving updates from #{account.handle}."
    end
  }

  def likes_with_links_as_html
    update(latest_tweet_id: likes_with_links.first.id) if likes_with_links.first.present?

    likes_with_links.map do |tweet|
      tweet.oembed(hide_media: true, hide_thread: true, omit_script: true).html
    end
  end

  private

  def likes_with_links
    @likes_with_links ||=
      if latest_tweet_id.present?
        TwitterWrapper::ApiClient.favorites(handle, latest_tweet_id).select(&:contains_link?)
      else
        TwitterWrapper::ApiClient.favorites(handle).select(&:contains_link?).first(5)
      end
  end
end
<commit_msg>Fix a bug with lambda syntax<commit_after># frozen_string_literal: true

class TwitterAccount < ApplicationRecord
  belongs_to :user

  validates :handle, presence: true
  validates :user, uniqueness: {
    scope: :handle, case_sensitive: false, message: lambda do |account, data|
      "#{data[:value].email} is already receiving updates from #{account.handle}."
    end
  }

  def likes_with_links_as_html
    update(latest_tweet_id: likes_with_links.first.id) if likes_with_links.first.present?

    likes_with_links.map do |tweet|
      tweet.oembed(hide_media: true, hide_thread: true, omit_script: true).html
    end
  end

  private

  def likes_with_links
    @likes_with_links ||=
      if latest_tweet_id.present?
        TwitterWrapper::ApiClient.favorites(handle, latest_tweet_id).select(&:contains_link?)
      else
        TwitterWrapper::ApiClient.favorites(handle).select(&:contains_link?).first(5)
      end
  end
end

{'fraction_non_alphanumeric': 0.0970873786407767, 'fraction_numerical': 0.0010787486515641855, 'mean_word_length': 4.196078431372549, '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': '7123205', 'n_tokens_mistral': 604, 'n_tokens_neox': 591, 'n_words': 128}