Class: Brio::Format::Pretty

Inherits:
Object
  • Object
show all
Defined in:
lib/brio/format/pretty.rb

Constant Summary collapse

WRAP_SIZE =
110

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePretty

Returns a new instance of Pretty.



17
18
19
# File 'lib/brio/format/pretty.rb', line 17

def initialize
  set_wrap
end

Instance Attribute Details

#wrapObject

Returns the value of attribute wrap.



7
8
9
# File 'lib/brio/format/pretty.rb', line 7

def wrap
  @wrap
end

Instance Method Details

#connection_stats(user) ⇒ Object



66
67
68
# File 'lib/brio/format/pretty.rb', line 66

def connection_stats( user )
  "<follows you: #{truth_to_tick_char user.follows_you} | you follow: #{truth_to_tick_char user.you_follow}>"
end

#print_post(post) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/brio/format/pretty.rb', line 28

def print_post( post )
  say "<%= color(\"@#{post.user.username}\", :username) %>"
  if post.text
    say "." * @wrap
    say "#{post.text.strip}"
    say "." * @wrap
  end
  say "<%= color('<id: #{post.id} | #{pretty_format_time(post.created_at)}#{reply_status post}> <replies #{post.num_replies} | stars #{post.num_stars} | reposts #{post.num_reposts}>', :end_line) %>"
  say "\n"
end


22
23
24
25
26
# File 'lib/brio/format/pretty.rb', line 22

def print_posts( posts )
  posts.each do |post|  
    print_post post
  end
end


45
46
47
48
49
50
51
52
53
54
55
# File 'lib/brio/format/pretty.rb', line 45

def print_user( user )
  say "\n"
  say "<%= color(\"#{user.name}\", :username) %> [#{user.username}]"
  if user.description.has_key? 'text'
    say "." * @wrap
    say "#{user.description.text.strip}"
    say "." * @wrap
  end
  say "<%= color('<followers: #{user.counts.followers} | following: #{user.counts.following} | since: #{pretty_format_time(user.created_at, %{%b %e %Y})}> #{connection_stats user}', :end_line) %>"
  say "\n"
end


39
40
41
42
43
# File 'lib/brio/format/pretty.rb', line 39

def print_users( users )
  users.each do |u|
    print_user u
  end
end

#reply_status(post) ⇒ Object



70
71
72
73
74
75
76
77
78
79
# File 'lib/brio/format/pretty.rb', line 70

def reply_status( post )
  msg = ""
  if post.reply_to
    msg << " | in reply to: #{post.reply_to}"
  end
  if post.repost_of
    msg << " | repost of: #{post.repost_of.id}"
  end
  msg
end

#set_wrapObject



57
58
59
60
61
62
63
64
# File 'lib/brio/format/pretty.rb', line 57

def set_wrap
  if $terminal.output_cols < WRAP_SIZE
    @wrap = $terminal.output_cols
  else
    @wrap = WRAP_SIZE
  end
  $terminal.wrap_at = @wrap
end