know_your_meme 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 85ce244c83c4c73f8957af1bd72717ff40255414994e86812dd69a1e4c1ebb48
4
+ data.tar.gz: 7884be206dfc39a61d546a17825b9ce97b705fe7edb1daf0c12bd4e9a3a4702a
5
+ SHA512:
6
+ metadata.gz: 87a77b5c34ea4874f19e86b65e69f2fd1dd6ceb1876cdc4fb42d62a804de23cd9376d0e241e212cf5311d73d6f723419fa27b90ad2af9d219239e00567769405
7
+ data.tar.gz: 3dc2783d48c8b314874cb6212983243608732574e0db87db7414e0a7e03ebd66ad3d960d3d62c60f07f43c535b17a80f1a042ccf160a066c3ac0130608764fd5
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ know_your_meme (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ mini_portile2 (2.3.0)
11
+ nokogiri (1.8.3)
12
+ mini_portile2 (~> 2.3.0)
13
+ rake (10.4.2)
14
+ rspec (3.7.0)
15
+ rspec-core (~> 3.7.0)
16
+ rspec-expectations (~> 3.7.0)
17
+ rspec-mocks (~> 3.7.0)
18
+ rspec-core (3.7.1)
19
+ rspec-support (~> 3.7.0)
20
+ rspec-expectations (3.7.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.7.0)
23
+ rspec-mocks (3.7.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.7.0)
26
+ rspec-support (3.7.1)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ bundler (~> 1.16)
33
+ know_your_meme!
34
+ nokogiri
35
+ rake (~> 10.0)
36
+ rspec
37
+
38
+ BUNDLED WITH
39
+ 1.16.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Annalisa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ ## Know Your Meme
2
+
3
+ This ruby gem provides a CLI to view the top 8 most popular memes and their stats according to knowyourmeme.com.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'know_your_meme'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install know_your_meme
20
+
21
+ ## Usage
22
+
23
+ Type the below and follow on-screen prompts:
24
+ $ know-your-meme
25
+
26
+ ## Development
27
+
28
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+
30
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/annalisarose/know_your_meme.
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "know_your_meme"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/know_your_meme'
4
+
5
+ KnowYourMeme::CLI.new.call
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,24 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "know_your_meme/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "know_your_meme"
8
+ spec.version = KnowYourMeme::VERSION
9
+ spec.authors = ["Annalisa Graziano"]
10
+ spec.email = ["arosegraz@gmail.com"]
11
+
12
+ spec.summary = "Retrieves retrieve stats on the top 8 entries from knowyourmeme.com's 'Popular' page."
13
+ spec.homepage = "https://github.com/annalisarose/know-your-meme-cli-gem"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.16"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "nokogiri", ">= 0"
24
+ end
@@ -0,0 +1,9 @@
1
+ #environment file
2
+
3
+ require 'nokogiri'
4
+ require 'open-uri'
5
+
6
+ require_relative "./know_your_meme/version"
7
+ require_relative "./know_your_meme/scraper"
8
+ require_relative "./know_your_meme/meme"
9
+ require_relative "./know_your_meme/cli"
@@ -0,0 +1,78 @@
1
+ class KnowYourMeme::CLI
2
+
3
+ def call
4
+ puts ""
5
+ puts "Welcome to the Know Your Meme CLI."
6
+ puts "I retrieve stats on the top 8 entries from knowyourmeme.com's 'Popular' page."
7
+ puts ""
8
+ KnowYourMeme::Scraper.scrape_memes
9
+ menu
10
+ exit
11
+ end
12
+
13
+ def menu
14
+ list_memes
15
+ prompt
16
+ get_input
17
+ end
18
+
19
+ def list_memes
20
+ puts "Top 8 Most Popular Memes:"
21
+ puts ""
22
+ memes = KnowYourMeme::Meme.all
23
+ memes.each.with_index(1) do |meme, index|
24
+ puts "#{index}. #{meme.name}"
25
+ end
26
+ end
27
+
28
+ def prompt
29
+ puts ""
30
+ puts "Enter the number of the meme on which you'd like more information, or enter 'list memes' to list memes, or enter 'exit' to exit program."
31
+ end
32
+
33
+ def reset
34
+ prompt
35
+ get_input
36
+ end
37
+
38
+ def get_input
39
+
40
+ input = gets.strip.downcase
41
+
42
+ if input.to_i > 0
43
+ index = input.to_i - 1
44
+
45
+ meme = KnowYourMeme::Meme.all[index]
46
+ KnowYourMeme::Scraper.scrape_meme_details(meme)
47
+
48
+ puts ""
49
+ puts meme.name
50
+ puts ""
51
+ puts "About"
52
+ puts meme.about
53
+ puts ""
54
+ puts "Origin"
55
+ puts meme.origin
56
+ puts ""
57
+ puts "Spread"
58
+ puts meme.spread
59
+ reset
60
+
61
+ elsif input == "exit"
62
+ puts ""
63
+ puts "Goodbye."
64
+
65
+ elsif input == "list memes"
66
+ puts ""
67
+ list_memes
68
+ reset
69
+
70
+ else
71
+ puts ""
72
+ puts "I'm not sure what you want."
73
+ reset
74
+ end
75
+
76
+ end
77
+
78
+ end
@@ -0,0 +1,19 @@
1
+ class KnowYourMeme::Meme
2
+ attr_accessor :name, :about, :origin, :spread, :url
3
+
4
+ @@all = []
5
+
6
+ def initialize(name, url, about = nil, origin = nil, spread = nil)
7
+ @name = name
8
+ @url = url
9
+ @about = about
10
+ @origin = origin
11
+ @spread = spread
12
+ @@all << self
13
+ end
14
+
15
+ def self.all
16
+ @@all
17
+ end
18
+
19
+ end
@@ -0,0 +1,22 @@
1
+ class KnowYourMeme::Scraper
2
+
3
+ BASE_URL = "https://knowyourmeme.com/memes/popular"
4
+
5
+ def self.scrape_memes
6
+ doc = Nokogiri::HTML(open(BASE_URL, 'User-Agent' => 'Chrome'))
7
+
8
+ doc.css('.entry-grid-body.infinite td')[0..7].each do |meme_entry|
9
+ name = meme_entry.css('h2 a').text.strip
10
+ url = "https://knowyourmeme.com#{meme_entry.css('a:first-child').attribute('href').value}"
11
+ KnowYourMeme::Meme.new(name, url)
12
+ end
13
+ end
14
+
15
+ def self.scrape_meme_details(meme)
16
+ url = meme.url
17
+ doc = Nokogiri::HTML(open(url, 'User-Agent' => 'Chrome'))
18
+ meme.about = doc.css('#about + p').text.strip
19
+ meme.spread = doc.css('#spread + p').text.strip
20
+ meme.origin = doc.css('#origin + p').text.strip
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module KnowYourMeme
2
+ VERSION = "0.1.0"
3
+ end
data/spec.md ADDED
@@ -0,0 +1,6 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+ - [ ] Have a CLI for interfacing with the application
5
+ - [ ] Pull data from an external source
6
+ - [ ] Implement both list and detail views
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: know_your_meme
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Annalisa Graziano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - arosegraz@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/know-your-meme
70
+ - bin/setup
71
+ - know_your_meme.gemspec
72
+ - lib/know_your_meme.rb
73
+ - lib/know_your_meme/cli.rb
74
+ - lib/know_your_meme/meme.rb
75
+ - lib/know_your_meme/scraper.rb
76
+ - lib/know_your_meme/version.rb
77
+ - spec.md
78
+ homepage: https://github.com/annalisarose/know-your-meme-cli-gem
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.7.7
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Retrieves retrieve stats on the top 8 entries from knowyourmeme.com's 'Popular'
102
+ page.
103
+ test_files: []