module T::Printable

Constants

LIST_HEADINGS
MONTH_IN_SECONDS
TWEET_HEADINGS
USER_HEADINGS

Private Instance Methods

build_long_list(list) click to toggle source
# File lib/t/printable.rb, line 10
def build_long_list(list)
  [list.id, ls_formatted_time(list), "@#{list.user.screen_name}", list.slug, list.member_count, list.subscriber_count, list.mode, list.description]
end
build_long_tweet(tweet) click to toggle source
# File lib/t/printable.rb, line 14
def build_long_tweet(tweet)
  [tweet.id, ls_formatted_time(tweet), "@#{tweet.user.screen_name}", decode_full_text(tweet, options['decode_uris']).gsub(/\n+/, ' ')]
end
build_long_user(user) click to toggle source
# File lib/t/printable.rb, line 18
def build_long_user(user)
  [user.id, ls_formatted_time(user), ls_formatted_time(user.status), user.statuses_count, user.favorites_count, user.listed_count, user.friends_count, user.followers_count, "@#{user.screen_name}", user.name, user.verified? ? 'Yes' : 'No', user.protected? ? 'Yes' : 'No', user.description.gsub(/\n+/, ' '), user.status? ? decode_full_text(user.status, options['decode_uris']).gsub(/\n+/, ' ') : nil, user.location, user.website.to_s]
end
csv_formatted_time(object, key = :created_at) click to toggle source
# File lib/t/printable.rb, line 22
def csv_formatted_time(object, key = :created_at)
  return nil if object.nil?
  time = object.send(key.to_sym).dup
  time.utc.strftime('%Y-%m-%d %H:%M:%S %z')
end
ls_formatted_time(object, key = :created_at, allow_relative = true) click to toggle source
# File lib/t/printable.rb, line 28
def ls_formatted_time(object, key = :created_at, allow_relative = true)
  return '' if object.nil?
  time = T.local_time(object.send(key.to_sym))
  if allow_relative && options['relative_dates']
    distance_of_time_in_words(time) + ' ago'
  elsif time > Time.now - MONTH_IN_SECONDS * 6
    time.strftime('%b %e %H:%M')
  else
    time.strftime('%b %e  %Y')
  end
end
print_attribute(array, attribute) click to toggle source
print_csv_list(list) click to toggle source
print_csv_tweet(tweet) click to toggle source
print_csv_user(user) click to toggle source
print_identicon(from_user, message) click to toggle source
print_lists(lists) click to toggle source
print_message(from_user, message) click to toggle source
print_table_with_headings(array, headings, format) click to toggle source
print_tweets(tweets) click to toggle source
print_users(users) click to toggle source
wrapped(message, options = {}) click to toggle source
# File lib/t/printable.rb, line 144
def wrapped(message, options = {})
  indent = options[:indent] || 0
  width = options[:width] || terminal_width - indent
  paras = message.split("\n\n")

  paras.map! do |unwrapped|
    unwrapped.strip.squeeze(' ').gsub(/.{1,#{width}}(?:\s|\Z)/) { ($& + 5.chr).gsub(/\n\005/, "\n").gsub(/\005/, "\n") }
  end

  lines = paras.inject([]) do |memo, para|
    memo.concat(para.split("\n").map { |line| line.insert(0, ' ' * indent) })
    memo.push ''
  end

  lines.pop
  lines
end