Class: Tweetwine::UI

Inherits:
Object
  • Object
show all
Defined in:
lib/tweetwine/ui.rb

Constant Summary collapse

COLOR_CODES =
{
  :cyan     => 36,
  :green    => 32,
  :magenta  => 35,
  :yellow   => 33
}.freeze
HASHTAG_REGEX =
/#[\w-]+/
USERNAME_REGEX =
/^(@\w+)|\s+(@\w+)/
URI_SCHEMES_TO_COLORIZE =
%w{http https}

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ UI

Returns a new instance of UI.



15
16
17
18
19
20
21
# File 'lib/tweetwine/ui.rb', line 15

def initialize(options = {})
  @in       = options[:in]            || $stdin
  @out      = options[:out]           || $stdout
  @err      = options[:err]           || $stderr
  @colors   = options[:colors]        || false
  @reverse  = options[:show_reverse]  || false
end

Instance Method Details

#confirm(msg) ⇒ Object



46
47
48
49
50
# File 'lib/tweetwine/ui.rb', line 46

def confirm(msg)
  @out.print "#{msg} [yN] "
  confirmation = @in.gets.strip
  confirmation.downcase[0, 1] == "y"
end

#error(msg) ⇒ Object



33
34
35
# File 'lib/tweetwine/ui.rb', line 33

def error(msg)
  @err.puts "ERROR: #{msg}"
end

#info(start_msg = "\n", end_msg = " done.") ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/tweetwine/ui.rb', line 23

def info(start_msg = "\n", end_msg = " done.")
  if block_given?
    @out.print start_msg
    yield
    @out.puts end_msg
  else
    @out.puts start_msg
  end
end

#prompt(prompt) ⇒ Object



41
42
43
44
# File 'lib/tweetwine/ui.rb', line 41

def prompt(prompt)
  @out.print "#{prompt}: "
  @in.gets.strip!
end

#show_status_preview(status) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/tweetwine/ui.rb', line 52

def show_status_preview(status)
  @out.puts <<-END

#{format_status(status)}

  END
end

#show_tweet(tweet) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/tweetwine/ui.rb', line 65

def show_tweet(tweet)
  if tweet.status?
    show_regular_tweet(tweet)
  else
    (tweet)
  end
end

#show_tweets(tweets) ⇒ Object



60
61
62
63
# File 'lib/tweetwine/ui.rb', line 60

def show_tweets(tweets)
  tweets = tweets.reverse if @reverse
  tweets.each { |t| show_tweet(t) }
end

#warn(msg) ⇒ Object



37
38
39
# File 'lib/tweetwine/ui.rb', line 37

def warn(msg)
  @out.puts "Warning: #{msg}"
end