view app/helpers/application_helper.rb @ 220:0e15b4db2da8

Remove unused variable
author nanaya <me@nanaya.pro>
date Thu, 27 May 2021 02:31:31 +0900
parents 70e90ea4b870
children 12287b32fbda
line wrap: on
line source

module ApplicationHelper
  include Twitter::TwitterText::Autolink

  def atom_id(id)
    "tag:rsstweet@nanaya.pro,2014:#{id}"
  end

  def expand_url(text, *urls)
    urls.flatten!

    urls = urls.reduce({}) do |result, u|
      if u.try(:[], :url)
        result[u[:url]] = u[:expanded_url]
      end

      result
    end

    text.gsub /https?:\/\/t\.co\/[A-Za-z0-9]+/ do |url|
      urls[url] || url
    end
  end

  def status_url(tweet)
    "https://twitter.com/#{tweet.user.screen_name.presence || '_'}/status/#{tweet.id}"
  end
end