Class: BggHotnessCLI::Game
- Inherits:
-
Object
- Object
- BggHotnessCLI::Game
- Defined in:
- lib/bgg-hotness-cli/game.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
Returns the value of attribute category.
-
#description ⇒ Object
Returns the value of attribute description.
-
#designer ⇒ Object
Returns the value of attribute designer.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#maxplayers ⇒ Object
Returns the value of attribute maxplayers.
-
#maxplaytime ⇒ Object
Returns the value of attribute maxplaytime.
-
#mechanic ⇒ Object
Returns the value of attribute mechanic.
-
#minage ⇒ Object
Returns the value of attribute minage.
-
#minplayers ⇒ Object
Returns the value of attribute minplayers.
-
#minplaytime ⇒ Object
Returns the value of attribute minplaytime.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#page ⇒ Object
Returns the value of attribute page.
-
#publisher ⇒ Object
Returns the value of attribute publisher.
-
#rank ⇒ Object
readonly
Returns the value of attribute rank.
-
#url ⇒ Object
Returns the value of attribute url.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #details_input ⇒ Object
- #display_details ⇒ Object
-
#full_description ⇒ Object
Displays full description.
-
#get_details ⇒ Object
Get the details from the game’s details page via API.
- #header ⇒ Object
-
#initialize(name, id, year, rank) ⇒ Game
constructor
Initialize with as much data as the list API gives for each game.
-
#publisher_designer ⇒ Object
Displays publisher(s) and designer(s).
Constructor Details
#initialize(name, id, year, rank) ⇒ Game
Initialize with as much data as the list API gives for each game
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/bgg-hotness-cli/game.rb', line 6 def initialize(name, id, year, rank) @name = name @id = id @year = year @rank = rank # Calculate page index of Page.all[] page_index = ((@rank.to_i - 1) / 10).floor # Put page into its game @page = BggHotnessCLI::Page.all[page_index] # Put game into its page BggHotnessCLI::Page.all[page_index].games << self end |
Instance Attribute Details
#category ⇒ Object
Returns the value of attribute category.
2 3 4 |
# File 'lib/bgg-hotness-cli/game.rb', line 2 def category @category end |
#description ⇒ Object
Returns the value of attribute description.
2 3 4 |
# File 'lib/bgg-hotness-cli/game.rb', line 2 def description @description end |
#designer ⇒ Object
Returns the value of attribute designer.
2 3 4 |
# File 'lib/bgg-hotness-cli/game.rb', line 2 def designer @designer end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/bgg-hotness-cli/game.rb', line 3 def id @id end |
#maxplayers ⇒ Object
Returns the value of attribute maxplayers.
2 3 4 |
# File 'lib/bgg-hotness-cli/game.rb', line 2 def maxplayers @maxplayers end |
#maxplaytime ⇒ Object
Returns the value of attribute maxplaytime.
2 3 4 |
# File 'lib/bgg-hotness-cli/game.rb', line 2 def maxplaytime @maxplaytime end |
#mechanic ⇒ Object
Returns the value of attribute mechanic.
2 3 4 |
# File 'lib/bgg-hotness-cli/game.rb', line 2 def mechanic @mechanic end |
#minage ⇒ Object
Returns the value of attribute minage.
2 3 4 |
# File 'lib/bgg-hotness-cli/game.rb', line 2 def minage @minage end |
#minplayers ⇒ Object
Returns the value of attribute minplayers.
2 3 4 |
# File 'lib/bgg-hotness-cli/game.rb', line 2 def minplayers @minplayers end |
#minplaytime ⇒ Object
Returns the value of attribute minplaytime.
2 3 4 |
# File 'lib/bgg-hotness-cli/game.rb', line 2 def minplaytime @minplaytime end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/bgg-hotness-cli/game.rb', line 3 def name @name end |
#page ⇒ Object
Returns the value of attribute page.
2 3 4 |
# File 'lib/bgg-hotness-cli/game.rb', line 2 def page @page end |
#publisher ⇒ Object
Returns the value of attribute publisher.
2 3 4 |
# File 'lib/bgg-hotness-cli/game.rb', line 2 def publisher @publisher end |
#rank ⇒ Object (readonly)
Returns the value of attribute rank.
3 4 5 |
# File 'lib/bgg-hotness-cli/game.rb', line 3 def rank @rank end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/bgg-hotness-cli/game.rb', line 2 def url @url end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
3 4 5 |
# File 'lib/bgg-hotness-cli/game.rb', line 3 def year @year end |
Instance Method Details
#details_input ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/bgg-hotness-cli/game.rb', line 101 def details_input choices = [ "Return to the list", "See full description", "See publisher(s) & designer(s)", "Open BGG page in your default browser" ] choices << "Return to game details" if @back_to_details choices << "Quit" # Set up prompt prompt = TTY::Prompt.new(active_color: :blue) # Set up greeting greeting = "Select an option:" # Capture input & display prompt @input = prompt.select(greeting, choices, cycle: true) # Parse user input if @input == choices[0] # If they chose 1st option, return to the list @page.display_page elsif @input == choices[1] # If they choose 2nd option, print full description @back_to_details = true full_description elsif @input == choices[2] # If they choose 3rd option, print publisher and designer @back_to_details = true publisher_designer elsif @input == choices[3] # If they choose 4th option, open URL with launchy and reset details page puts puts "Attempting to open URL..." puts Launchy.open(@url) @input = @rank # Set input to rank so correct game is chosen display_details elsif @input == choices[4] && @back_to_details # If they choose back to game details, go back to game details @back_to_details = false display_details elsif @input == choices.last # If they quit, run "goodbye" method BggHotnessCLI::CLI.goodbye end end |
#display_details ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/bgg-hotness-cli/game.rb', line 37 def display_details # Variable for indentation string to make it easy to change @indent = "· " # Print loading message. # This is cleared by separator after load finishes, # and generally won't be on the screen for long. puts puts "Loading details..." puts # Check to see if details exist, and scrapes if needed get_details @back_to_details = false header # 2-4 players • 60-90 minutes • ages 12+ puts "#{@minplayers}–#{@maxplayers} players • #{@minplaytime}–#{@maxplaytime} minutes • ages #{@minage}+" # https://boardgamegeek.com/boardgame/ID puts "#{@url}" puts # Use wrap method to add indentation & word wrap puts "DESCRIPTION:" puts wrap("#{@description[0..140]}...",@indent) puts # Use print_array method to print arrays (with wrap method) print_array("categories", "category", @category, @indent) print_array("mechanics", "mechanic", @mechanic, @indent) # See what user wants to do next details_input end |
#full_description ⇒ Object
Displays full description
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/bgg-hotness-cli/game.rb', line 76 def full_description header # Use wrap method to add indentation & word wrap puts "DESCRIPTION:" puts wrap("#{@description}",@indent) puts # See what user wants to do next details_input end |
#get_details ⇒ Object
Get the details from the game’s details page via API
28 29 30 31 32 33 34 35 |
# File 'lib/bgg-hotness-cli/game.rb', line 28 def get_details # If the description is nil, it needs to be scraped. # Otherwise, all data should be in memory, so skip this. if @description.nil? BggHotnessCLI::Scraper.new("https://boardgamegeek.com/xmlapi2/thing?id=#{@id}").get_details(self) end end |
#header ⇒ Object
20 21 22 23 24 25 |
# File 'lib/bgg-hotness-cli/game.rb', line 20 def header # Print header BggHotnessCLI::CLI.header puts puts "#{@rank}. #{@name} (#{@year})" end |
#publisher_designer ⇒ Object
Displays publisher(s) and designer(s)
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/bgg-hotness-cli/game.rb', line 89 def publisher_designer header # Use print_array method to print arrays (with wrap method) print_array("publishers", "publisher", @publisher, @indent) print_array("designers", "designer", @designer, @indent) puts # See what user wants to do next details_input end |