Permalink
Browse files

Change sort flag to enum

  • Loading branch information...
1 parent c67413a commit f5b1a81a90c4c7eebaf8b585581e778dfe9ca49d @sferik committed Jul 8, 2012
Showing with 364 additions and 415 deletions.
  1. +2 −0 Gemfile
  2. +8 −53 lib/t/cli.rb
  3. +1 −7 lib/t/list.rb
  4. +30 −26 lib/t/printable.rb
  5. +1 −7 lib/t/search.rb
  6. +258 −258 spec/cli_spec.rb
  7. +32 −32 spec/list_spec.rb
  8. +32 −32 spec/search_spec.rb
View
@@ -8,4 +8,6 @@ platforms :mri do
gem 'ruby-prof'
end
+gem 'thor', :github => 'wycats/thor', :branch => 'enum'
+
gemspec
View
@@ -202,16 +202,10 @@ def direct_messages_sent
desc "groupies [USER]", "Returns the list of people who follow you but you don't follow back."
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "favorites", :aliases => "-v", :type => :boolean, :default => false, :desc => "Sort by number of favorites."
- method_option "followers", :aliases => "-f", :type => :boolean, :default => false, :desc => "Sort by number of followers."
- method_option "friends", :aliases => "-e", :type => :boolean, :default => false, :desc => "Sort by number of friends."
method_option "id", :aliases => "-i", :type => "boolean", :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "listed", :aliases => "-d", :type => :boolean, :default => false, :desc => "Sort by number of list memberships."
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "posted", :aliases => "-p", :type => :boolean, :default => false, :desc => "Sort by the time when Twitter account was posted."
method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
- method_option "tweets", :aliases => "-t", :type => :boolean, :default => false, :desc => "Sort by number of Tweets."
- method_option "tweeted", :aliases => "-w", :type => :boolean, :default => false, :desc => "Sort by the time of the last Tweet."
+ method_option "sort", :aliases => "-s", :type => :string, :enum => %w(favorites followers friends listed screen_name since tweets tweeted), :default => "screen_name", :desc => "Specify the order of the results.", :banner => "ORDER"
method_option "unsorted", :aliases => "-u", :type => :boolean, :default => false, :desc => "Output is not sorted."
def groupies(user=nil)
if user
@@ -376,16 +370,10 @@ def follow(user, *users)
desc "followings [USER]", "Returns a list of the people you follow on Twitter."
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "favorites", :aliases => "-v", :type => :boolean, :default => false, :desc => "Sort by number of favorites."
- method_option "followers", :aliases => "-f", :type => :boolean, :default => false, :desc => "Sort by number of followers."
- method_option "friends", :aliases => "-e", :type => :boolean, :default => false, :desc => "Sort by number of friends."
method_option "id", :aliases => "-i", :type => "boolean", :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "listed", :aliases => "-d", :type => :boolean, :default => false, :desc => "Sort by number of list memberships."
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "posted", :aliases => "-p", :type => :boolean, :default => false, :desc => "Sort by the time when Twitter account was posted."
method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
- method_option "tweets", :aliases => "-t", :type => :boolean, :default => false, :desc => "Sort by number of Tweets."
- method_option "tweeted", :aliases => "-w", :type => :boolean, :default => false, :desc => "Sort by the time of the last Tweet."
+ method_option "sort", :aliases => "-s", :type => :string, :enum => %w(favorites followers friends listed screen_name since tweets tweeted), :default => "screen_name", :desc => "Specify the order of the results.", :banner => "ORDER"
method_option "unsorted", :aliases => "-u", :type => :boolean, :default => false, :desc => "Output is not sorted."
def followings(user=nil)
if user
@@ -408,16 +396,10 @@ def followings(user=nil)
desc "followers [USER]", "Returns a list of the people who follow you on Twitter."
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "favorites", :aliases => "-v", :type => :boolean, :default => false, :desc => "Sort by number of favorites."
- method_option "followers", :aliases => "-f", :type => :boolean, :default => false, :desc => "Sort by number of followers."
- method_option "friends", :aliases => "-e", :type => :boolean, :default => false, :desc => "Sort by number of friends."
method_option "id", :aliases => "-i", :type => "boolean", :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "listed", :aliases => "-d", :type => :boolean, :default => false, :desc => "Sort by number of list memberships."
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "posted", :aliases => "-p", :type => :boolean, :default => false, :desc => "Sort by the time when Twitter account was posted."
method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
- method_option "tweets", :aliases => "-t", :type => :boolean, :default => false, :desc => "Sort by number of Tweets."
- method_option "tweeted", :aliases => "-w", :type => :boolean, :default => false, :desc => "Sort by the time of the last Tweet."
+ method_option "sort", :aliases => "-s", :type => :string, :enum => %w(favorites followers friends listed screen_name since tweets tweeted), :default => "screen_name", :desc => "Specify the order of the results.", :banner => "ORDER"
method_option "unsorted", :aliases => "-u", :type => :boolean, :default => false, :desc => "Output is not sorted."
def followers(user=nil)
if user
@@ -440,16 +422,10 @@ def followers(user=nil)
desc "friends [USER]", "Returns the list of people who you follow and follow you back."
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "favorites", :aliases => "-v", :type => :boolean, :default => false, :desc => "Sort by number of favorites."
- method_option "followers", :aliases => "-f", :type => :boolean, :default => false, :desc => "Sort by number of followers."
- method_option "friends", :aliases => "-e", :type => :boolean, :default => false, :desc => "Sort by number of friends."
method_option "id", :aliases => "-i", :type => "boolean", :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "listed", :aliases => "-d", :type => :boolean, :default => false, :desc => "Sort by number of list memberships."
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "posted", :aliases => "-p", :type => :boolean, :default => false, :desc => "Sort by the time when Twitter account was posted."
method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
- method_option "tweets", :aliases => "-t", :type => :boolean, :default => false, :desc => "Sort by number of Tweets."
- method_option "tweeted", :aliases => "-w", :type => :boolean, :default => false, :desc => "Sort by the time of the last Tweet."
+ method_option "sort", :aliases => "-s", :type => :string, :enum => %w(favorites followers friends listed screen_name since tweets tweeted), :default => "screen_name", :desc => "Specify the order of the results.", :banner => "ORDER"
method_option "unsorted", :aliases => "-u", :type => :boolean, :default => false, :desc => "Output is not sorted."
def friends(user=nil)
if user
@@ -480,16 +456,10 @@ def friends(user=nil)
desc "leaders [USER]", "Returns the list of people who you follow but don't follow you back."
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "favorites", :aliases => "-v", :type => :boolean, :default => false, :desc => "Sort by number of favorites."
- method_option "followers", :aliases => "-f", :type => :boolean, :default => false, :desc => "Sort by number of followers."
- method_option "friends", :aliases => "-e", :type => :boolean, :default => false, :desc => "Sort by number of friends."
method_option "id", :aliases => "-i", :type => "boolean", :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "listed", :aliases => "-d", :type => :boolean, :default => false, :desc => "Sort by number of list memberships."
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "posted", :aliases => "-p", :type => :boolean, :default => false, :desc => "Sort by the time when Twitter account was posted."
method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
- method_option "tweets", :aliases => "-t", :type => :boolean, :default => false, :desc => "Sort by number of Tweets."
- method_option "tweeted", :aliases => "-w", :type => :boolean, :default => false, :desc => "Sort by the time of the last Tweet."
+ method_option "sort", :aliases => "-s", :type => :string, :enum => %w(favorites followers friends listed screen_name since tweets tweeted), :default => "screen_name", :desc => "Specify the order of the results.", :banner => "ORDER"
method_option "unsorted", :aliases => "-u", :type => :boolean, :default => false, :desc => "Output is not sorted."
def leaders(user=nil)
if user
@@ -522,11 +492,8 @@ def leaders(user=nil)
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
method_option "id", :aliases => "-i", :type => "boolean", :default => false, :desc => "Specify user via ID instead of screen name."
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "members", :aliases => "-m", :type => :boolean, :default => false, :desc => "Sort by number of members."
- method_option "mode", :aliases => "-o", :type => :boolean, :default => false, :desc => "Sort by mode."
- method_option "posted", :aliases => "-p", :type => :boolean, :default => false, :desc => "Sort by the time when Twitter list was posted."
method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
- method_option "subscribers", :aliases => "-s", :type => :boolean, :default => false, :desc => "Sort by number of subscribers."
+ method_option "sort", :aliases => "-s", :type => :string, :enum => %w(members mode posted slug subscribers), :default => "slug", :desc => "Specify the order of the results.", :banner => "ORDER"
method_option "unsorted", :aliases => "-u", :type => :boolean, :default => false, :desc => "Output is not sorted."
def lists(user=nil)
if user
@@ -724,17 +691,11 @@ def status(status_id)
desc "suggest [USER]", "Returns a listing of Twitter users' accounts you might enjoy following."
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "favorites", :aliases => "-v", :type => :boolean, :default => false, :desc => "Sort by number of favorites."
- method_option "followers", :aliases => "-f", :type => :boolean, :default => false, :desc => "Sort by number of followers."
- method_option "friends", :aliases => "-e", :type => :boolean, :default => false, :desc => "Sort by number of friends."
method_option "id", :aliases => "-i", :type => "boolean", :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "listed", :aliases => "-d", :type => :boolean, :default => false, :desc => "Sort by number of list memberships."
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
method_option "number", :aliases => "-n", :type => :numeric, :default => DEFAULT_NUM_RESULTS, :desc => "Limit the number of results."
- method_option "posted", :aliases => "-p", :type => :boolean, :default => false, :desc => "Sort by the time when Twitter account was posted."
method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
- method_option "tweets", :aliases => "-t", :type => :boolean, :default => false, :desc => "Sort by number of Tweets."
- method_option "tweeted", :aliases => "-w", :type => :boolean, :default => false, :desc => "Sort by the time of the last Tweet."
+ method_option "sort", :aliases => "-s", :type => :string, :enum => %w(favorites followers friends listed screen_name since tweets tweeted), :default => "screen_name", :desc => "Specify the order of the results.", :banner => "ORDER"
method_option "unsorted", :aliases => "-u", :type => :boolean, :default => false, :desc => "Output is not sorted."
def suggest(user=nil)
if user
@@ -848,16 +809,10 @@ def update(message)
desc "users USER [USER...]", "Returns a list of users you specify."
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "favorites", :aliases => "-v", :type => :boolean, :default => false, :desc => "Sort by number of favorites."
- method_option "followers", :aliases => "-f", :type => :boolean, :default => false, :desc => "Sort by number of followers."
- method_option "friends", :aliases => "-e", :type => :boolean, :default => false, :desc => "Sort by number of friends."
method_option "id", :aliases => "-i", :type => "boolean", :default => false, :desc => "Specify input as Twitter user IDs instead of screen names."
- method_option "listed", :aliases => "-d", :type => :boolean, :default => false, :desc => "Sort by number of list memberships."
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "posted", :aliases => "-p", :type => :boolean, :default => false, :desc => "Sort by the time when Twitter account was posted."
method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
- method_option "tweets", :aliases => "-t", :type => :boolean, :default => false, :desc => "Sort by number of Tweets."
- method_option "tweeted", :aliases => "-w", :type => :boolean, :default => false, :desc => "Sort by the time of the last Tweet."
+ method_option "sort", :aliases => "-s", :type => :string, :enum => %w(favorites followers friends listed screen_name since tweets tweeted), :default => "screen_name", :desc => "Specify the order of the results.", :banner => "ORDER"
method_option "unsorted", :aliases => "-u", :type => :boolean, :default => false, :desc => "Output is not sorted."
def users(user, *users)
users.unshift(user)
View
@@ -97,16 +97,10 @@ def information(list)
desc "members [USER/]LIST", "Returns the members of a Twitter list."
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
- method_option "followers", :aliases => "-v", :type => :boolean, :default => false, :desc => "Sort by total number of favorites."
- method_option "followers", :aliases => "-f", :type => :boolean, :default => false, :desc => "Sort by total number of followers."
- method_option "friends", :aliases => "-e", :type => :boolean, :default => false, :desc => "Sort by total number of friends."
method_option "id", :aliases => "-i", :type => "boolean", :default => false, :desc => "Specify user via ID instead of screen name."
- method_option "listed", :aliases => "-d", :type => :boolean, :default => false, :desc => "Sort by number of list memberships."
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
- method_option "posted", :aliases => "-p", :type => :boolean, :default => false, :desc => "Sort by the time when Twitter account was posted."
method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
- method_option "tweets", :aliases => "-t", :type => :boolean, :default => false, :desc => "Sort by total number of Tweets."
- method_option "tweeted", :aliases => "-w", :type => :boolean, :default => false, :desc => "Sort by the time of the last Tweet."
+ method_option "sort", :aliases => "-s", :type => :string, :enum => %w(favorites followers friends listed screen_name since tweets tweeted), :default => "screen_name", :desc => "Specify the order of the results.", :banner => "ORDER"
method_option "unsorted", :aliases => "-u", :type => :boolean, :default => false, :desc => "Output is not sorted."
def members(list)
owner, list = list.split('/')
View
@@ -56,16 +56,18 @@ def print_csv_user(user)
end
def print_lists(lists)
- lists = lists.sort_by{|list| list.slug.downcase} unless options['unsorted']
- if options['posted']
- lists = lists.sort_by{|user| user.created_at}
- elsif options['members']
- lists = lists.sort_by{|user| user.member_count}
- elsif options['mode']
- lists = lists.sort_by{|user| user.mode}
- elsif options['subscribers']
- lists = lists.sort_by{|user| user.subscriber_count}
- end
+ lists = case options['sort']
+ when 'members'
+ lists.sort_by{|user| user.member_count}
+ when 'mode'
+ lists.sort_by{|user| user.mode}
+ when 'posted'
+ lists.sort_by{|user| user.created_at}
+ when 'subscribers'
+ lists.sort_by{|user| user.subscriber_count}
+ else
+ lists.sort_by{|list| list.slug.downcase}
+ end unless options['unsorted']
lists.reverse! if options['reverse']
if options['csv']
require 'csv'
@@ -145,22 +147,24 @@ def print_statuses(statuses)
end
def print_users(users)
- users = users.sort_by{|user| user.screen_name.downcase} unless options['unsorted']
- if options['posted']
- users = users.sort_by{|user| user.created_at}
- elsif options['favorites']
- users = users.sort_by{|user| user.favourites_count}
- elsif options['followers']
- users = users.sort_by{|user| user.followers_count}
- elsif options['friends']
- users = users.sort_by{|user| user.friends_count}
- elsif options['listed']
- users = users.sort_by{|user| user.listed_count}
- elsif options['tweets']
- users = users.sort_by{|user| user.statuses_count}
- elsif options['tweeted']
- users = users.sort_by{|user| user.status.created_at rescue Time.at(0)}
- end
+ users = case options['sort']
+ when 'favorites'
+ users.sort_by{|user| user.favourites_count}
+ when 'followers'
+ users.sort_by{|user| user.followers_count}
+ when 'friends'
+ users.sort_by{|user| user.friends_count}
+ when 'listed'
+ users.sort_by{|user| user.listed_count}
+ when 'since'
+ users.sort_by{|user| user.created_at}
+ when 'tweets'
+ users.sort_by{|user| user.statuses_count}
+ when 'tweeted'
+ users.sort_by{|user| user.status.created_at rescue Time.at(0)}
+ else
+ users.sort_by{|user| user.screen_name.downcase}
+ end unless options['unsorted']
users.reverse! if options['reverse']
if options['csv']
require 'csv'
Oops, something went wrong. Retry.

0 comments on commit f5b1a81

Please sign in to comment.