class Pry::SendTweet::BaseCommand

Public Class Methods

inherited(kls) click to toggle source
# File lib/pry/send_tweet/commands/base_command.rb, line 12
def self.inherited(kls)
  kls.group 'Twitter'
end

Public Instance Methods

process(*args) click to toggle source
# File lib/pry/send_tweet/commands/base_command.rb, line 16
def process(*args)
  if nil == _pry_.config.twitter
    raise Pry::CommandError, "_pry_.config.twitter is nil!\n" \
                             "Please set the required keys and tokens to send " \
                             "tweets using Twitters API. \n" \
                             "Visit https://gitlab/trebor8/fry-send_tweet.rb to learn how."
  end
end

Private Instance Methods

box_height() click to toggle source
# File lib/pry/send_tweet/commands/base_command.rb, line 31
def box_height
  Pry::SendTweet::DEFAULT_BOX_HEIGHT
end
box_width() click to toggle source
# File lib/pry/send_tweet/commands/base_command.rb, line 35
def box_width
  _pry_.config.twitter.box_width || Pry::SendTweet::DEFAULT_BOX_WIDTH
end
default_read_size() click to toggle source
# File lib/pry/send_tweet/commands/base_command.rb, line 27
def default_read_size
  _pry_.config.twitter.default_read_size || Pry::SendTweet::DEFAULT_READ_SIZE
end
numbered_list(title, ary) { |item, index+1| ... } click to toggle source
# File lib/pry/send_tweet/commands/base_command.rb, line 60
def numbered_list(title, ary)
  title = "\n#{bold(title.chomp)}\n\n"
  title + ary.map.with_index { |item, index| yield(item, index+1) }.join("\n")
end
search_str_for_users(*ary) click to toggle source
# File lib/pry/send_tweet/commands/base_command.rb, line 39
def search_str_for_users(*ary)
  ary.map do |str|
    if str.start_with?('https://twitter.com')
      path = URI.parse(URI.escape(str)).path
      path.split('/').reject(&:empty?).first
    elsif str.start_with?('@')
      str[1..-1]
    else
      str
    end
  end
end
time_format() click to toggle source
# File lib/pry/send_tweet/commands/base_command.rb, line 65
def time_format
  "%-d %b %Y, %-I:%M:%S %p"
end
twitter() click to toggle source
# File lib/pry/send_tweet/commands/base_command.rb, line 69
def twitter
  @twitter ||= _pry_.binding_stack[-1].eval('_twitter_')
end
word_wrap(text, options = {}) click to toggle source

With thanks to ActionView for this method

# File lib/pry/send_tweet/commands/base_command.rb, line 53
def word_wrap(text, options = {})
 line_width = box_width
 text.split("\n").collect! do |line|
   line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
 end * "\n"
end