Module: FlickrCli::Menu
- Defined in:
- lib/menu.rb
Class Method Summary collapse
- .contacts ⇒ Object
- .download_and_print(picked_photo) ⇒ Object
- .end_program ⇒ Object
- .good_by_message ⇒ Object
- .main_menu ⇒ Object
- .menu_for(contact, page = 1) ⇒ Object
Class Method Details
.contacts ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/menu.rb', line 73 def self.contacts contacts ||= flickr.contacts.getList.map(&:username).sort choose do || .prompt = "Choose a contact" contacts.each do |contact| .choice(contact.to_sym) { FlickrCli::Menu.(contact) } end end end |
.download_and_print(picked_photo) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/menu.rb', line 44 def self.download_and_print(picked_photo) if @cached_art["photo_#{picked_photo.id}"] puts @cached_art["photo_#{picked_photo.id}"] else photos = flickr.photos.getSizes(:photo_id => picked_photo.id) download_url = nil ["Large", "Medium"].each do |style| if picture = photos.find{ |photo| photo.label == style } download_url = picture.source end break if download_url end @cached_art["photo_#{picked_photo.id}"] = AsciiArt.new(download_url).to_ascii_art(width: 150, color: true) puts @cached_art["photo_#{picked_photo.id}"] end end |
.end_program ⇒ Object
39 40 41 42 |
# File 'lib/menu.rb', line 39 def self.end_program say self. exit end |
.good_by_message ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/menu.rb', line 63 def self. ['Be that way.', "Goodbye - I'll never love again.", 'I love my kid, is that a crime?', 'Smell u l8er sk8ter', 'How could you do this to me? Now?', 'Listen to Lilys, Swervedriver, and The Swirilies.', 'Flickr? I hardly know her'].sample end |
.main_menu ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/menu.rb', line 5 def self. choose do || .prompt = "What do you want to explore?" .choice("Your Photostream") { (flickr.test.login.username) } .choice("Contacts' Photostream") { contacts } .choice("Quit") { end_program } end end |
.menu_for(contact, page = 1) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/menu.rb', line 14 def self.(contact, page = 1) the_page = page user_id = flickr.people.findByUsername(:username => contact).id photos = flickr.photos.search(:user_id => user_id, :page => the_page) choose do || .prompt = "Pick a File (page #{the_page})" photos.map(&:title).each do |photo| .choice(photo) do # When you choose a photo... FlickrCli::Menu.download_and_print(photos.detect{|x| x.title == photo}) puts "Press ENTER to continue" do_nothing = STDIN.gets self.(FlickrCli::Menu.(contact, the_page)) end end .choice("More >>") { self.(contact, (the_page+1) )} .choice("Back <<") { self.(contact, (the_page-1) )} if the_page > 1 .choice("~(==::Main::==)~") { self. } .choice("Quit") { self.end_program } end end |