Skip to content

Commit

Permalink
Use Array.new with a block instead of .times.collect
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Jan 19, 2016
1 parent efdba93 commit 04051e1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions lib/t/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def direct_messages
array = direct_messages.collect do |direct_message|
[direct_message.id, ls_formatted_time(direct_message), "@#{direct_message.sender.screen_name}", decode_full_text(direct_message, options['decode_uris']).gsub(/\n+/, ' ')]
end
format = options['format'] || DIRECT_MESSAGE_HEADINGS.size.times.collect { '%s' }
format = options['format'] || Array.new(DIRECT_MESSAGE_HEADINGS.size) { '%s' }
print_table_with_headings(array, DIRECT_MESSAGE_HEADINGS, format)
else
direct_messages.each do |direct_message|
Expand Down Expand Up @@ -183,7 +183,7 @@ def direct_messages_sent
array = direct_messages.collect do |direct_message|
[direct_message.id, ls_formatted_time(direct_message), "@#{direct_message.recipient.screen_name}", decode_full_text(direct_message, options['decode_uris']).gsub(/\n+/, ' ')]
end
format = options['format'] || DIRECT_MESSAGE_HEADINGS.size.times.collect { '%s' }
format = options['format'] || Array.new(DIRECT_MESSAGE_HEADINGS.size) { '%s' }
print_table_with_headings(array, DIRECT_MESSAGE_HEADINGS, format)
else
direct_messages.each do |direct_message|
Expand Down Expand Up @@ -733,7 +733,7 @@ def status(status_id) # rubocop:disable CyclomaticComplexity
say [status.id, csv_formatted_time(status), status.user.screen_name, decode_full_text(status, options['decode_uris']), status.retweet_count, status.favorite_count, strip_tags(status.source), location].to_csv
elsif options['long']
array = [status.id, ls_formatted_time(status), "@#{status.user.screen_name}", decode_full_text(status, options['decode_uris']).gsub(/\n+/, ' '), status.retweet_count, status.favorite_count, strip_tags(status.source), location]
format = options['format'] || status_headings.size.times.collect { '%s' }
format = options['format'] || Array.new(status_headings.size) { '%s' }
print_table_with_headings([array], status_headings, format)
else
array = []
Expand Down Expand Up @@ -824,7 +824,7 @@ def trend_locations
array = places.collect do |place|
[place.woeid, place.parent_id, place.place_type, place.name, place.country]
end
format = options['format'] || TREND_HEADINGS.size.times.collect { '%s' }
format = options['format'] || Array.new(TREND_HEADINGS.size) { '%s' }
print_table_with_headings(array, TREND_HEADINGS, format)
else
print_attribute(places, :name)
Expand Down
8 changes: 4 additions & 4 deletions lib/t/printable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def print_lists(lists)
array = lists.collect do |list|
build_long_list(list)
end
format = options['format'] || LIST_HEADINGS.size.times.collect { '%s' }
format = options['format'] || Array.new(LIST_HEADINGS.size) { '%s' }
print_table_with_headings(array, LIST_HEADINGS, format)
else
print_attribute(lists, :full_name)
Expand Down Expand Up @@ -138,7 +138,7 @@ def print_identicon(from_user, message)
# Save 6 chars for icon, ensure at least 3 lines long
lines = wrapped(HTMLEntities.new.decode(message), indent: 2, width: terminal_width - (6 + 5))
lines.unshift(set_color(" @#{from_user}", :bold, :yellow))
lines.push(*(3 - lines.length).times.map { '' })
lines.push(*Array.new(3 - lines.length) { '' })

$stdout.puts lines.zip(icon.lines).map { |x, i| " #{i || ' '}#{x}" }
end
Expand Down Expand Up @@ -173,7 +173,7 @@ def print_tweets(tweets)
array = tweets.collect do |tweet|
build_long_tweet(tweet)
end
format = options['format'] || TWEET_HEADINGS.size.times.collect { '%s' }
format = options['format'] || Array.new(TWEET_HEADINGS.size) { '%s' }
print_table_with_headings(array, TWEET_HEADINGS, format)
else
tweets.each do |tweet|
Expand Down Expand Up @@ -212,7 +212,7 @@ def print_users(users) # rubocop:disable CyclomaticComplexity
array = users.collect do |user|
build_long_user(user)
end
format = options['format'] || USER_HEADINGS.size.times.collect { '%s' }
format = options['format'] || Array.new(USER_HEADINGS.size) { '%s' }
print_table_with_headings(array, USER_HEADINGS, format)
else
print_attribute(users, :screen_name)
Expand Down
2 changes: 1 addition & 1 deletion lib/t/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def all(query)
array = tweets.collect do |tweet|
[tweet.id, ls_formatted_time(tweet), "@#{tweet.user.screen_name}", decode_full_text(tweet, options['decode_uris']).gsub(/\n+/, ' ')]
end
format = options['format'] || TWEET_HEADINGS.size.times.collect { '%s' }
format = options['format'] || Array.new(TWEET_HEADINGS.size) { '%s' }
print_table_with_headings(array, TWEET_HEADINGS, format)
else
say unless tweets.empty?
Expand Down
4 changes: 2 additions & 2 deletions lib/t/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def all
require 'csv'
say TWEET_HEADINGS.to_csv
elsif options['long'] && STDOUT.tty?
headings = TWEET_HEADINGS.size.times.collect do |index|
headings = Array.new(TWEET_HEADINGS.size) do |index|
TWEET_HEADINGS_FORMATTING[index] % TWEET_HEADINGS[index]
end
print_table([headings])
Expand Down Expand Up @@ -170,7 +170,7 @@ def users(user_id, *user_ids)
require 'csv'
say TWEET_HEADINGS.to_csv
elsif options['long'] && STDOUT.tty?
headings = TWEET_HEADINGS.size.times.collect do |index|
headings = Array.new(TWEET_HEADINGS.size) do |index|
TWEET_HEADINGS_FORMATTING[index] % TWEET_HEADINGS[index]
end
print_table([headings])
Expand Down

0 comments on commit 04051e1

Please sign in to comment.