reddit-ruby 1.0.7 → 1.0.8

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
  SHA1:
3
- metadata.gz: 8000199fe4ed99318ccf99d2c202df572777cbfa
4
- data.tar.gz: 43a66e1f26350621d6cfa10ca07bbbc95257abba
3
+ metadata.gz: 01e754fa54a6ee2a525bf32971f1ac71265cbf6b
4
+ data.tar.gz: 7a02fda2801b73df4bb47911d3f60086126f8020
5
5
  SHA512:
6
- metadata.gz: 4337a5c0c7d5890fdb100e5ee5953301f2b1f2e79780b98185b4f48e88a5767cb353c7e581b2707a47c8ce41433d64c85ebfec2748512932bf68a29370acd246
7
- data.tar.gz: a81e986d178a3e82878fb4879e2eac446363a167e484bb99f52786670df468dd6ab7b2924fad82102bc03690f095cb90e379998471cd16251a2485cd646a7c87
6
+ metadata.gz: 9f0a22f0be3d18a74385cd2c7e57a2022c71e72e2f7c67a392e49d5ab3f12f1f37df138ae01542cb93cf490b64a665cd41d4763136af7bf68bf5f2eec7679961
7
+ data.tar.gz: 4f343fcce0dda6b13c48cf05045aaeeb2410650d8efd31ef174156b611353f73f0e3301583e841582c5b834822b1c3d7ce56ee02fb93bc4e0a6834ca41719eee
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- reddit-ruby (1.0.7)
4
+ reddit-ruby (1.0.8)
5
5
  colorize
6
6
  nokogiri
7
7
 
@@ -1,7 +1,8 @@
1
1
  class Reddit::CLI
2
2
  def call
3
- puts "Here's the current hot list on r/ruby"
4
- show_posts
3
+ @subreddit = ARGV[0] || "ruby"
4
+ puts "Here's the current hot list on r/#{@subreddit}"
5
+ show_posts(@subreddit)
5
6
  menu
6
7
  end
7
8
 
@@ -20,7 +21,7 @@ class Reddit::CLI
20
21
  while input != "exit"
21
22
  puts ""
22
23
  puts "> Enter the number of the post you'd like more info on:"
23
- input = gets.strip.downcase
24
+ input = STDIN.gets.chomp.downcase
24
25
 
25
26
  if input.to_i > 0
26
27
  show_post(input.to_i-1)
@@ -45,9 +46,8 @@ class Reddit::CLI
45
46
  return "#{upvotes} #{score}"
46
47
  end
47
48
 
48
- def show_posts
49
- Reddit::Scraper.scrape
50
- @posts = Reddit::Scraper.scrape
49
+ def show_posts(subreddit)
50
+ @posts = Reddit::Scraper.scrape(subreddit)
51
51
  @posts.each_with_index do |post, i|
52
52
  upvotes = get_score_text(i)
53
53
  index = "#{i + 1}"
@@ -71,7 +71,7 @@ class Reddit::CLI
71
71
  puts "2. Show hot posts"
72
72
  puts "3. Exit"
73
73
  puts ""
74
- input = gets.strip.downcase
74
+ input = STDIN.gets.chomp.downcase
75
75
  if input.to_i == 1
76
76
  openInBrowser(post[:url])
77
77
  elsif input.to_i == 2
@@ -1,7 +1,8 @@
1
1
  class Reddit::Scraper
2
2
  attr_accessor :title, :author, :timestamp, :comments, :upvotes, :url
3
- def self.scrape
4
- doc = Nokogiri::HTML(open("https://www.reddit.com/r/ruby", 'User-Agent' => 'ruby-reddit'))
3
+ def self.scrape(subreddit)
4
+ url = "https://www.reddit.com/r/#{subreddit}"
5
+ doc = Nokogiri::HTML(open(url, 'User-Agent' => 'ruby-reddit'))
5
6
  posts = []
6
7
  postsList = doc.css('#siteTable > div.thing.link').first(10)
7
8
  postsList.each do |post|
@@ -1,3 +1,3 @@
1
1
  module Reddit
2
- VERSION = "1.0.7"
2
+ VERSION = "1.0.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reddit-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logan McAnsh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-08 00:00:00.000000000 Z
11
+ date: 2017-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler