Class: Stars::Client
- Inherits:
-
Object
- Object
- Stars::Client
- Defined in:
- lib/stars/client.rb
Instance Attribute Summary collapse
-
#posts ⇒ Object
Returns the value of attribute posts.
Instance Method Summary collapse
-
#display(service = nil) ⇒ Object
Displays all of the star tables and information we have.
-
#headings ⇒ Object
The headings used in the resulting printed table.
-
#initialize(cmd) ⇒ Client
constructor
Initializes a new Client.
-
#print_posts(posts) ⇒ Object
This does the actual printing of posts.
-
#show(id) ⇒ Object
Show more information about a particular post.
-
#star_loop ⇒ Object
Run a loop FOREVER until we kill it or we make a selection.
Constructor Details
Instance Attribute Details
#posts ⇒ Object
Returns the value of attribute posts.
9 10 11 |
# File 'lib/stars/client.rb', line 9 def posts @posts end |
Instance Method Details
#display(service = nil) ⇒ Object
Displays all of the star tables and information we have.
Returns nothing.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/stars/client.rb', line 43 def display(service=nil) Stars.config.prompt_for_service if Stars.installed_services.empty? if service && service != 'add' if Stars.services.include? service posts = service.constantize.posts else puts "Service \"#{service}\" is unknown." exit end else posts = Stars.installed_services.collect{ |service| service.constantize.posts }.flatten end @posts = Post.filter(posts) puts print_posts(@posts) end |
#headings ⇒ Object
The headings used in the resulting printed table.
This returns an Array of headings.
95 96 97 98 99 100 101 102 |
# File 'lib/stars/client.rb', line 95 def headings [ '', 'Service', 'Stars', {:value => 'The Hotness', :alignment => :center } ] end |
#print_posts(posts) ⇒ Object
This does the actual printing of posts.
posts - an Array of Post objects
It loops through the Array of posts and sends them to ‘terminal-table`.
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/stars/client.rb', line 78 def print_posts(posts) table do |t| t.headings = headings posts.each_with_index do |post,i| t << [ { :value => i+1, :alignment => :right }, post.service.capitalize, { :value => post.stars_count, :alignment => :center }, post.short_name ] end end end |
#show(id) ⇒ Object
Show more information about a particular post.
id - the Integer id entered by the user, which we map to a Post
Returns nothing (although does delegate to the Post to show #more).
66 67 68 69 70 71 |
# File 'lib/stars/client.rb', line 66 def show(id) post = @posts[id.to_i-1] return puts("\nMake a valid selection. Pretty please?\n") unless post puts post.more display end |
#star_loop ⇒ Object
Run a loop FOREVER until we kill it or we make a selection.
Returns nothing.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/stars/client.rb', line 28 def star_loop selection = '' while true puts "Type the number of the post that you want to learn about" print " (or hit return to view all again, you ego-maniac) >> " selection = $stdin.gets.chomp break if ['','q','quit','exit','fuckthis'].include?(selection.downcase) show(selection) end display if selection == '' end |