From 21a5152acfdd6a1442b84e12d3699263ac0804cd Mon Sep 17 00:00:00 2001 From: joshua stein Date: Mon, 2 May 2016 17:56:56 -0500 Subject: [PATCH] post_to_twitter: only count extensions with letters as domains --- script/post_to_twitter | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/script/post_to_twitter b/script/post_to_twitter index a87de17..44ac0c4 100755 --- a/script/post_to_twitter +++ b/script/post_to_twitter @@ -46,9 +46,13 @@ Time.now - 1.days).order(:id).each_with_index do |s,x| # if there are any urls in the title, they should be sized (at least) to a # twitter t.co url - left_len -= (title.scan(/[^ ]\..{2,10}/i).map{|u| [ 0, + left_len -= (title.scan(/[^ ]\.[a-z]{2,10}/i).map{|u| [ 0, Twitter::TCO_LEN ].max }.inject(:+)).to_i + if left_len < -3 + left_len = -3 + end + if title.bytesize > left_len status = title[0, left_len - 3] + "..." + status else