bgg-hotness-cli 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56be050438c908ba1e6bb22c3f1211e83559b6f423431a0f45d9792fe3061eba
4
- data.tar.gz: 020f580b7653eb580ae0001ce02f792614a37cb14e406de6dd6416542cb55a90
3
+ metadata.gz: bc2de6031f26fec351be1d1edb8f8501b4fd0b21a08049623adb168a9709ad51
4
+ data.tar.gz: 7944aab38e12d7eb4bb9c7d1bea9281fa754c71ee89402283bd8f907961c179f
5
5
  SHA512:
6
- metadata.gz: 9540f941f8893b9329c8a4e432e86e191f17347679dece1c0c224e31bb9192c842f21787acbe2db54415b181127c97508a7246d29df7029566736c7f417c5c39
7
- data.tar.gz: 6012de1f19fb3926150c581757f0476248cf7c583bb1685164c23a0ae744e72f126b0095ceb32b6402f868df22c4f7510ba81f3ddc658fc004fd8378f136e7d0
6
+ metadata.gz: b4d8f3d15dc42d93e2be60bd1eb3eff1dc1122f8b9e02f5d83f05046c920d1d7ebd628b385fced9d9cdaadf3a96447bbec358c91433e894db662f9a2a6c54e92
7
+ data.tar.gz: 0a7956c19df56a732dd735aa793a121a07e5fa580090077d71530ea1bf97c5d5fa28cca441a323c05ab066396aa483c196d998d186147514834c41d160f851ce
data/README.md CHANGED
@@ -31,14 +31,14 @@ gem install bgg-hotness-cli
31
31
 
32
32
  Run `bin/bgg-hotness-cli` in your terminal for a quickstart.
33
33
 
34
- Or `require 'bgg-hotness-cli` and create a `BggHotnessCLI` object with `.new.run` methods wherever you want it.
34
+ Or `require 'bgg-hotness-cli` and create run with `BggHotnessCLI::CLI.run`.
35
35
 
36
36
  For example:
37
37
 
38
38
  ```ruby
39
39
  irb
40
40
  require 'bgg-hotness-cli'
41
- BggHotnessCLI.new.run
41
+ BggHotnessCLI::CLI.run
42
42
  ```
43
43
 
44
44
  Once you're in the interface, use ↑/↓ arrows to navigate between options and press Enter to select your choice.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "bgg-hotness-cli"
3
- spec.version = "0.1.3"
3
+ spec.version = "0.1.4"
4
4
  spec.authors = ["'Josh Ellis'"]
5
5
  spec.email = ['joshe523@gmail.com']
6
6
 
@@ -4,4 +4,4 @@ require "bundler/setup"
4
4
  require "bgg-hotness-cli"
5
5
 
6
6
  # Everything happens in a single instance of CommandLineInterface
7
- BggHotnessCLI.new.run
7
+ BggHotnessCLI::CLI.run
@@ -1,38 +1,13 @@
1
- require_relative './bgg-hotness-cli/scraper.rb'
2
- require_relative './bgg-hotness-cli/game.rb'
3
- require_relative './bgg-hotness-cli/wrap.rb'
4
- require_relative './bgg-hotness-cli/page.rb'
1
+ require 'nokogiri'
2
+ require 'open-uri'
5
3
  require 'launchy'
6
4
  require 'tty-prompt'
7
5
 
8
- class BggHotnessCLI
9
- # Displays goodbye and ends program
10
- def self.goodbye
11
- puts
12
- puts "Goodbye!"
13
- puts
14
- return
15
- end
16
-
17
- def self.header
18
- puts "\e[H\e[2J"
19
- puts
20
- puts "BGG Hotness CLI"
21
- end
22
-
23
- # Runs program by creating empty pages,
24
- # doing a scrape of the hot list, adding games to pages,
25
- # and printing the first 10 items on the list.
26
- def run
27
- # Create empty pages
28
- Page.make_pages
6
+ module BggHotnessCLI
7
+ end
29
8
 
30
- # Scrape list, which creates game instances
31
- # and adds them to their pages in order.
32
- Scraper.new("https://www.boardgamegeek.com/xmlapi2/hot?boardgame").game_list
33
-
34
- Page.all[0].display_page
35
- end
36
-
37
- # NOTE: #run must be last so other methods can load.
38
- end
9
+ require_relative './bgg-hotness-cli/scraper.rb'
10
+ require_relative './bgg-hotness-cli/game.rb'
11
+ require_relative './bgg-hotness-cli/helpers.rb'
12
+ require_relative './bgg-hotness-cli/page.rb'
13
+ require_relative './bgg-hotness-cli/cli.rb'
@@ -0,0 +1,31 @@
1
+ class BggHotnessCLI::CLI
2
+ # Displays goodbye and ends program
3
+ def self.goodbye
4
+ puts
5
+ puts "Goodbye!"
6
+ puts
7
+ return
8
+ end
9
+
10
+ def self.header
11
+ puts "\e[H\e[2J"
12
+ puts
13
+ puts "BGG Hotness CLI"
14
+ end
15
+
16
+ # Runs program by creating empty pages,
17
+ # doing a scrape of the hot list, adding games to pages,
18
+ # and printing the first 10 items on the list.
19
+ def self.run
20
+ # Create empty pages
21
+ BggHotnessCLI::Page.make_pages
22
+
23
+ # Scrape list, which creates game instances
24
+ # and adds them to their pages in order.
25
+ BggHotnessCLI::Scraper.new("https://www.boardgamegeek.com/xmlapi2/hot?boardgame").game_list
26
+
27
+ BggHotnessCLI::Page.all[0].display_page
28
+ end
29
+
30
+ # NOTE: #run must be last so other methods can load.
31
+ end
@@ -1,4 +1,4 @@
1
- class Game
1
+ class BggHotnessCLI::Game
2
2
  attr_accessor :page, :description, :minplayers, :maxplayers, :minplaytime, :maxplaytime, :minage, :category, :mechanic, :publisher, :designer, :url
3
3
  attr_reader :name, :id, :year, :rank
4
4
 
@@ -12,14 +12,14 @@ class Game
12
12
  # Calculate page index of Page.all[]
13
13
  page_index = ((@rank.to_i - 1) / 10).floor
14
14
  # Put page into its game
15
- @page = Page.all[page_index]
15
+ @page = BggHotnessCLI::Page.all[page_index]
16
16
  # Put game into its page
17
- Page.all[page_index].games << self
17
+ BggHotnessCLI::Page.all[page_index].games << self
18
18
  end
19
19
 
20
20
  def header
21
21
  # Print header
22
- BggHotnessCLI.header
22
+ BggHotnessCLI::CLI.header
23
23
  puts
24
24
  puts "#{@rank}. #{@name} (#{@year})"
25
25
  end
@@ -30,7 +30,7 @@ class Game
30
30
  # If the description is nil, it needs to be scraped.
31
31
  # Otherwise, all data should be in memory, so skip this.
32
32
  if @description.nil?
33
- Scraper.new("https://boardgamegeek.com/xmlapi2/thing?id=#{@id}").get_details(self)
33
+ BggHotnessCLI::Scraper.new("https://boardgamegeek.com/xmlapi2/thing?id=#{@id}").get_details(self)
34
34
  end
35
35
  end
36
36
 
@@ -65,43 +65,37 @@ class Game
65
65
  puts
66
66
 
67
67
  # Use print_array method to print arrays (with wrap method)
68
- print_array("categories", "category", @category)
69
- print_array("mechanics", "mechanic", @mechanic)
68
+ print_array("categories", "category", @category, @indent)
69
+ print_array("mechanics", "mechanic", @mechanic, @indent)
70
70
 
71
71
  # See what user wants to do next
72
72
  details_input
73
73
  end
74
74
 
75
- # Prints array with commas as needed
76
- def print_array(plural, single, array)
77
- # Sometimes new games have empty fields.
78
- # Don't do anything if array is empty.
79
- if array.size != 0
80
- puts array.size > 1 ? "#{plural.upcase}: " : "#{single.upcase}: "
81
-
82
- # Initialize variable for holding output string
83
- output = ""
84
- array.each_with_index do |item,idx|
85
- output += item
86
-
87
- # if there's more than one item and this isn't the last item, add commas
88
- if item != array.last && array.size > 1
89
-
90
- # print an & before last item
91
- if idx == array.size - 2
92
- output += ", & "
93
-
94
- # otherwise, just print a comma and space
95
- else
96
- output += ", "
97
- end
98
- end
99
- end
100
-
101
- # print the output with word-wrapping
102
- puts wrap(output, @indent)
103
- puts
104
- end
75
+ # Displays full description
76
+ def full_description
77
+ header
78
+
79
+ # Use wrap method to add indentation & word wrap
80
+ puts "DESCRIPTION:"
81
+ puts wrap("#{@description}",@indent)
82
+ puts
83
+
84
+ # See what user wants to do next
85
+ details_input
86
+ end
87
+
88
+ # Displays publisher(s) and designer(s)
89
+ def publisher_designer
90
+ header
91
+
92
+ # Use print_array method to print arrays (with wrap method)
93
+ print_array("publishers", "publisher", @publisher, @indent)
94
+ print_array("designers", "designer", @designer, @indent)
95
+ puts
96
+
97
+ # See what user wants to do next
98
+ details_input
105
99
  end
106
100
 
107
101
  def details_input
@@ -150,34 +144,8 @@ class Game
150
144
  display_details
151
145
  elsif @input == choices.last
152
146
  # If they quit, run "goodbye" method
153
- BggHotnessCLI.goodbye
147
+ BggHotnessCLI::CLI.goodbye
154
148
  end
155
149
  end
156
150
 
157
- # Displays full description
158
- def full_description
159
- header
160
-
161
- # Use wrap method to add indentation & word wrap
162
- puts "DESCRIPTION:"
163
- puts wrap("#{@description}",@indent)
164
- puts
165
-
166
- # See what user wants to do next
167
- details_input
168
- end
169
-
170
- # Displays publisher(s) and designer(s)
171
- def publisher_designer
172
- header
173
-
174
- # Use print_array method to print arrays (with wrap method)
175
- print_array("publishers", "publisher", @publisher)
176
- print_array("designers", "designer", @designer)
177
- puts
178
-
179
- # See what user wants to do next
180
- details_input
181
- end
182
-
183
151
  end
@@ -0,0 +1,37 @@
1
+ # via http://www.java2s.com/Code/Ruby/String/WordwrappingLinesofText.htm
2
+
3
+ def wrap(s, indent, width=78)
4
+ s.gsub(/(.{1,#{width}})(\s+|\Z)/, "#{indent}\\1\n")
5
+ end
6
+
7
+ # Prints array with commas as needed
8
+ def print_array(plural, single, array, indent)
9
+ # Sometimes new games have empty fields.
10
+ # Don't do anything if array is empty.
11
+ if array.size != 0
12
+ puts array.size > 1 ? "#{plural.upcase}: " : "#{single.upcase}: "
13
+
14
+ # Initialize variable for holding output string
15
+ output = ""
16
+ array.each_with_index do |item,idx|
17
+ output += item
18
+
19
+ # if there's more than one item and this isn't the last item, add commas
20
+ if item != array.last && array.size > 1
21
+
22
+ # print an & before last item
23
+ if idx == array.size - 2
24
+ output += ", & "
25
+
26
+ # otherwise, just print a comma and space
27
+ else
28
+ output += ", "
29
+ end
30
+ end
31
+ end
32
+
33
+ # print the output with word-wrapping
34
+ puts wrap(output, indent)
35
+ puts
36
+ end
37
+ end
@@ -1,6 +1,6 @@
1
1
  # Each page is a list of 10 games.
2
2
  # In total, the app has 5 pages (50 games).
3
- class Page
3
+ class BggHotnessCLI::Page
4
4
  attr_accessor :start_rank, :end_rank, :games, :page_number
5
5
 
6
6
  @@all = []
@@ -22,7 +22,7 @@ class Page
22
22
  # Displays list of games between @start_rank and @end_rank
23
23
 
24
24
  # Print header
25
- BggHotnessCLI.header
25
+ BggHotnessCLI::CLI.header
26
26
  puts "The top #{@start_rank}–#{@end_rank} hot games on BGG."
27
27
  puts
28
28
 
@@ -59,20 +59,20 @@ class Page
59
59
  # If user selects next part of the list...
60
60
  if @end_rank == 50
61
61
  # ...if at the end of the list (50), display the first page
62
- Page.all[0].display_page
62
+ BggHotnessCLI::Page.all[0].display_page
63
63
  else
64
64
  # ...otherwise, display the next page
65
65
  # this works because the first page is [0] index,
66
66
  # but it's page # is 1, meaning this will show
67
67
  # the second page (which is at all[1]).
68
68
  # TODO: make this less confusing?
69
- Page.all[@page_number].display_page
69
+ BggHotnessCLI::Page.all[@page_number].display_page
70
70
  end
71
71
  elsif @input == 'quit'
72
72
  # If they quit, run "goodbye" method
73
- BggHotnessCLI.goodbye
73
+ BggHotnessCLI::CLI.goodbye
74
74
  else
75
- # Otherwise, navigate to selected game
75
+ # Otherwise, @input is a game. Display its details.
76
76
  @input.display_details
77
77
  end
78
78
 
@@ -96,7 +96,7 @@ class Page
96
96
  _start_rank = 1 # temp local variable
97
97
  _end_rank = 10 # temp local variable
98
98
  5.times do
99
- Page.new(_start_rank, _end_rank)
99
+ BggHotnessCLI::Page.new(_start_rank, _end_rank)
100
100
  _start_rank += 10
101
101
  _end_rank += 10
102
102
  end
@@ -1,7 +1,4 @@
1
- require 'nokogiri'
2
- require 'open-uri'
3
-
4
- class Scraper
1
+ class BggHotnessCLI::Scraper
5
2
 
6
3
  # Initialize with an API path to open
7
4
  def initialize(path)
@@ -20,7 +17,7 @@ class Scraper
20
17
  year = item.css('yearpublished')[0]['value']
21
18
 
22
19
  # Create a new instance of Game with item data
23
- game = Game.new(name, id, year, rank)
20
+ game = BggHotnessCLI::Game.new(name, id, year, rank)
24
21
  end
25
22
 
26
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bgg-hotness-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - "'Josh Ellis'"
@@ -101,10 +101,11 @@ files:
101
101
  - bin/setup
102
102
  - img/start-page.jpg
103
103
  - lib/bgg-hotness-cli.rb
104
+ - lib/bgg-hotness-cli/cli.rb
104
105
  - lib/bgg-hotness-cli/game.rb
106
+ - lib/bgg-hotness-cli/helpers.rb
105
107
  - lib/bgg-hotness-cli/page.rb
106
108
  - lib/bgg-hotness-cli/scraper.rb
107
- - lib/bgg-hotness-cli/wrap.rb
108
109
  homepage: https://github.com/imjoshellis/bgg-hotness-cli
109
110
  licenses:
110
111
  - MIT
@@ -1,5 +0,0 @@
1
- # via http://www.java2s.com/Code/Ruby/String/WordwrappingLinesofText.htm
2
-
3
- def wrap(s, indent, width=78)
4
- s.gsub(/(.{1,#{width}})(\s+|\Z)/, "#{indent}\\1\n")
5
- end