Skip to content

Commit

Permalink
Refactor printable methods a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed May 1, 2012
1 parent 12a180b commit d3c422a
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions lib/t/printable.rb
Expand Up @@ -15,13 +15,34 @@ def self.included(base)

private

def build_long_list(list)
created_at = list.created_at > 6.months.ago ? list.created_at.strftime("%b %e %H:%M") : list.created_at.strftime("%b %e %Y")
[list.id, created_at, list.full_name, number_with_delimiter(list.member_count), number_with_delimiter(list.subscriber_count), list.mode, list.description]
end

def build_long_status(status)
created_at = status.created_at > 6.months.ago ? status.created_at.strftime("%b %e %H:%M") : status.created_at.strftime("%b %e %Y")
[status.id, created_at, "@#{status.user.screen_name}", HTMLEntities.new.decode(status.text).gsub(/\n+/, ' ')]
end

def build_long_user(user)
created_at = user.created_at > 6.months.ago ? user.created_at.strftime("%b %e %H:%M") : user.created_at.strftime("%b %e %Y")
[user.id, created_at, number_with_delimiter(user.statuses_count), number_with_delimiter(user.favourites_count), number_with_delimiter(user.listed_count), number_with_delimiter(user.friends_count), number_with_delimiter(user.followers_count), "@#{user.screen_name}", user.name]
end

def print_csv_list(list)
created_at = list.created_at.utc.strftime("%Y-%m-%d %H:%M:%S %z")
say [list.id, created_at, list.user.screen_name, list.slug, list.member_count, list.subscriber_count, list.mode, list.description].to_csv
end

def print_csv_status(status)
say [status.id, status.created_at.utc.strftime("%Y-%m-%d %H:%M:%S %z"), status.user.screen_name, HTMLEntities.new.decode(status.text)].to_csv
created_at = status.created_at.utc.strftime("%Y-%m-%d %H:%M:%S %z")
say [status.id, created_at, status.user.screen_name, HTMLEntities.new.decode(status.text)].to_csv
end

def print_csv_user(user)
created_at = user.created_at.utc.strftime("%Y-%m-%d %H:%M:%S %z")
say [user.id, created_at, user.statuses_count, user.favourites_count, user.listed_count, user.friends_count, user.followers_count, user.screen_name, user.name].to_csv
end

def print_in_columns(array)
Expand Down Expand Up @@ -49,12 +70,11 @@ def print_lists(lists)
if options['csv']
say ["ID", "Created at", "Screen name", "Slug", "Members", "Subscribers", "Mode", "Description"].to_csv unless lists.empty?
lists.each do |list|
say [list.id, list.created_at.utc.strftime("%Y-%m-%d %H:%M:%S %z"), list.user.screen_name, list.slug, list.member_count, list.subscriber_count, list.mode, list.description].to_csv
print_csv_list(list)
end
elsif options['long']
array = lists.map do |list|
created_at = list.created_at > 6.months.ago ? list.created_at.strftime("%b %e %H:%M") : list.created_at.strftime("%b %e %Y")
[list.id, created_at, list.full_name, number_with_delimiter(list.member_count), number_with_delimiter(list.subscriber_count), list.mode, list.description]
build_long_list(list)
end
if STDOUT.tty?
headings = ["ID", "Created at", "Slug", "Members", "Subscribers", "Mode", "Description"]
Expand Down Expand Up @@ -129,12 +149,11 @@ def print_users(users)
if options['csv']
say ["ID", "Since", "Tweets", "Favorites", "Listed", "Following", "Followers", "Screen name", "Name"].to_csv unless users.empty?
users.each do |user|
say [user.id, user.created_at.utc.strftime("%Y-%m-%d %H:%M:%S %z"), user.statuses_count, user.favourites_count, user.listed_count, user.friends_count, user.followers_count, user.screen_name, user.name].to_csv
print_csv_user(user)
end
elsif options['long']
array = users.map do |user|
created_at = user.created_at > 6.months.ago ? user.created_at.strftime("%b %e %H:%M") : user.created_at.strftime("%b %e %Y")
[user.id, created_at, number_with_delimiter(user.statuses_count), number_with_delimiter(user.favourites_count), number_with_delimiter(user.listed_count), number_with_delimiter(user.friends_count), number_with_delimiter(user.followers_count), "@#{user.screen_name}", user.name]
build_long_user(user)
end
if STDOUT.tty?
headings = ["ID", "Since", "Tweets", "Favorites", "Listed", "Following", "Followers", "Screen name", "Name"]
Expand Down

0 comments on commit d3c422a

Please sign in to comment.