asciiartist 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 297eec4f45a0f8ed26ca0d2f3c5a626ea04d4a805cafd720e7634c3c80f064c9
4
+ data.tar.gz: 9f39cb3dd67e0ef742e21fe252a18aeab1f57c71b3c5446270e568a45d10e64b
5
+ SHA512:
6
+ metadata.gz: 527fd4b667c955eaab263380a9f1d975743f15359bc4961d945dcd64ed1d82eb65b69c19fd54f367623a60548ab9a12db167b8a4f943a58dc1734de8b05cb007
7
+ data.tar.gz: c03517002c0d34bf0e2f9ebb9889fa74102247bb2c4331f43b4a5799753e1a5b38c9ed3b8c38777d46b1ff0f5e999b4c500616113a9e3a708540d2300b69ee6f
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ asciiartist (0.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ asciiartist!
15
+
16
+ BUNDLED WITH
17
+ 2.0.1
@@ -0,0 +1,47 @@
1
+ #AsciiArtist
2
+
3
+ ###This Ruby Gem is a CLI that scrapes and serves Ascii Art from www.AsciiArt.eu. Use this application as a fun terminal based way of browsing Ascii Art pieces, or even sprucing up your source code.
4
+
5
+ Not sure what Ascii Art is? Here is an example:
6
+
7
+ ,'``.._ ,'``.
8
+ :,--._:)\,:,._,.: All Glory to
9
+ :`--,'' :`...';\ the HYPNO TOAD!
10
+ `,' `---' `.
11
+ / :
12
+ / \
13
+ ,' :\.___,-.
14
+ `...,---'``````-..._ |: \
15
+ ( ) ;: ) \ _,-.
16
+ `. ( // `' \
17
+ : `.// ) ) , ;
18
+ ,-|`. _,'/ ) ) ,' ,'
19
+ ( :`.`-..____..=:.-': . _,' ,'
20
+ `,'\ ``--....-)=' `._, \ ,') _ '``._
21
+ _.-/ _ `. (_) / )' ; / \ \`-.'
22
+ `--( `-:`. `' ___..' _,-' |/ `.)
23
+ `-. `.`.``-----``--, .'
24
+ |/`.\`' ,','); SSt
25
+ ` (/ (/
26
+
27
+ ## Installation
28
+
29
+ $ gem install asciiartist
30
+
31
+ ## Usage
32
+
33
+ Type the below and follow the on screen prompts.
34
+
35
+ $ asciiartist
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Allenfp/asciiartist. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
40
+
41
+ ## License
42
+
43
+ This gem is available as open source under the terms of the [MIT License](https://github.com/Allenfp/asciiartist/blob/master/LICENSE.txt).
44
+
45
+ ## Other Information
46
+
47
+ This gem was produced as a "just for fun" project by Allen Partlow. I am in no way affiliated with Asciiart.eu.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'asciiartist'
3
+ s.version = '0.1.0'
4
+ s.date = '2019-04-14'
5
+ s.summary = "A nifty CLI that allows users to access ascii art from the command line!"
6
+ s.description = "Spruce up your code base with Ascii Art available directly from the command line!"
7
+ s.authors = ["Allen Partlow"]
8
+ s.email = ['allenfp@gmail.com']
9
+ s.files = ["bin/setup","bin/asciiartist","bin/console","config/environment.rb","asciiartist.gemspec","README.md","Rakefile","lib/asciiartist.rb","lib/art.rb","lib/cli.rb","lib/scraper.rb","gemfile","Gemfile.lock"]
10
+
11
+ s.homepage = ""
12
+ s.license = 'MIT'
13
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ s.require_paths = ["lib"]
15
+
16
+ s.add_development_dependency "bundler", "~> 1.10"
17
+ s.add_development_dependency "rake", "~> 10.0"
18
+ s.add_development_dependency "rspec", ">= 0"
19
+ s.add_development_dependency "nokogiri", ">= 0"
20
+ s.add_development_dependency "pry", ">= 0"
21
+
22
+ end
@@ -0,0 +1,6 @@
1
+
2
+ #!/usr/bin/env ruby
3
+
4
+ require 'asciiartist'
5
+
6
+ AsciiArtist::CLI.new.welcome
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "asciiartist"
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
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
@@ -0,0 +1,7 @@
1
+ require 'pry'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ require_relative '../lib/scraper'
6
+ require_relative '../lib/art'
7
+ require_relative '../lib/cli'
data/gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+
4
+ gemspec
@@ -0,0 +1,25 @@
1
+ class AsciiArtist::Art
2
+
3
+ attr_accessor :art_text, :index
4
+ @@all = []
5
+ @@favorites = []
6
+
7
+ def initialize(art, index)
8
+ @art_text = art
9
+ @index = index
10
+ @@all << self
11
+ end
12
+
13
+ def self.all
14
+ @@all
15
+ end
16
+
17
+ def self.clear
18
+ @@all = []
19
+ end
20
+
21
+ def add_to_favorites
22
+ @@favorites << self
23
+ end
24
+
25
+ end
@@ -0,0 +1,4 @@
1
+ module AsciiArtist
2
+ end
3
+
4
+ require_relative '/Users/allenpartlow/Dropbox/asciiartist/config/environment.rb'
@@ -0,0 +1,133 @@
1
+ class AsciiArtist::CLI
2
+
3
+ def welcome()
4
+ puts "\n\n\n\n\n\n\n\n\n\n\n\n
5
+
6
+ Welcome to...
7
+
8
+ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄
9
+ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌
10
+ ▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▀▀▀▀█░█▀▀▀▀ ▀▀▀▀█░█▀▀▀▀
11
+ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌
12
+ ▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄▄▄ ▐░▌ ▐░▌ ▐░▌
13
+ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌ ▐░▌ ▐░▌
14
+ ▐░█▀▀▀▀▀▀▀█░▌ ▀▀▀▀▀▀▀▀▀█░▌▐░▌ ▐░▌ ▐░▌
15
+ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌
16
+ ▐░▌ ▐░▌ ▄▄▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄▄▄ ▄▄▄▄█░█▄▄▄▄ ▄▄▄▄█░█▄▄▄▄
17
+ ▐░▌ ▐░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌
18
+ ▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀
19
+ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄
20
+ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌
21
+ ▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀█░▌ ▀▀▀▀█░█▀▀▀▀ ▀▀▀▀█░█▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▀▀▀▀█░█▀▀▀▀
22
+ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌
23
+ ▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄█░▌ ▐░▌ ▐░▌ ▐░█▄▄▄▄▄▄▄▄▄ ▐░▌
24
+ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌ ▐░▌ ▐░▌ ▐░░░░░░░░░░░▌ ▐░▌
25
+ ▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀█░█▀▀ ▐░▌ ▐░▌ ▀▀▀▀▀▀▀▀▀█░▌ ▐░▌
26
+ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌
27
+ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▄▄▄▄█░█▄▄▄▄ ▄▄▄▄▄▄▄▄▄█░▌ ▐░▌
28
+ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌ ▐░▌
29
+ ▀ ▀ ▀ ▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀
30
+
31
+
32
+ ... A CLI web scraping project that reads from www.asciiart.eu !!
33
+ \n\nFor the best results, maximize your terminal window.
34
+ "
35
+ sleep 2
36
+ start
37
+ end
38
+
39
+ def start
40
+
41
+ #Scrape and serve top level categories.
42
+ level_1_category_choice_url = get_categories('https://www.asciiart.eu/')
43
+
44
+ #Scrape and serve sub-level categories.
45
+ level_2_category_choice_url = get_categories(level_1_category_choice_url)
46
+
47
+ #Create art objects.
48
+ art_doc = fetch_page(level_2_category_choice_url)
49
+ parse_art(art_doc)
50
+ show_art
51
+
52
+ #Clear Objects and Restart
53
+ clear_art
54
+ start
55
+
56
+ end
57
+
58
+ def get_categories(url)
59
+ doc = fetch_page(url)
60
+ categories = parse_categories(doc)
61
+ print_and_select_categories(categories)
62
+ puts "Please select a category by number:"
63
+ category_selection = gets.to_i
64
+ sub_doc = categories[category_selection][:url]
65
+ sub_doc
66
+ end
67
+
68
+ def print_and_select_categories(categories)
69
+ puts "Please select a category."
70
+ puts "|==================================================|"
71
+ categories.each.with_index { |cat, index|
72
+ puts "\t#{index}) \t" + cat[:title]
73
+ }
74
+ puts "|==================================================|"
75
+ end
76
+
77
+ def parse_art(art_doc)
78
+ art_doc.css('body > div.d-flex > div > div.workarea.p-2.px-sm-4.pb-sm-4 > div.asciiarts.mt-3 > div > pre').each.with_index { |x, index|
79
+ create_art(x.text, index)
80
+
81
+ }
82
+ end
83
+
84
+ def create_art(art, index)
85
+ AsciiArtist::Art.new(art, index)
86
+ end
87
+
88
+ def clear_art
89
+ AsciiArtist::Art.clear
90
+ end
91
+
92
+ def parse_categories(doc)
93
+ categories = []
94
+ doc.css('#directory > div > ul > li').each { |x|
95
+ begin
96
+ categories << {
97
+ title: x.children.text,
98
+ url: "https://www.asciiart.eu" + x.children.attr('href').value
99
+ }
100
+ rescue
101
+ next
102
+ end
103
+ }
104
+ categories
105
+ end
106
+
107
+ def show_art
108
+
109
+ puts "Press Enter Key to cycle through gallery, or type 'quit' to return to main menu. "
110
+
111
+ AsciiArtist::Art.all.each { |x|
112
+
113
+ action = gets.chomp
114
+
115
+ if action == "quit"
116
+ break
117
+ else
118
+ puts "|-- --|\n\n"
119
+ puts x.art_text
120
+ puts "\n\n|-- --|"
121
+ end
122
+
123
+ }
124
+
125
+ puts "End of gallery, returning to main menu."
126
+ sleep 2
127
+ end
128
+
129
+ def fetch_page(url)
130
+ AsciiArtist::Scraper.new.get_categories(url)
131
+ end
132
+
133
+ end
@@ -0,0 +1,7 @@
1
+ class AsciiArtist::Scraper
2
+
3
+ def get_categories(url)
4
+ Nokogiri::HTML(open(url))
5
+ end
6
+
7
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asciiartist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Allen Partlow
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-14 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: rspec
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
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Spruce up your code base with Ascii Art available directly from the command
84
+ line!
85
+ email:
86
+ - allenfp@gmail.com
87
+ executables:
88
+ - asciiartist
89
+ - console
90
+ - setup
91
+ extensions: []
92
+ extra_rdoc_files: []
93
+ files:
94
+ - Gemfile.lock
95
+ - README.md
96
+ - Rakefile
97
+ - asciiartist.gemspec
98
+ - bin/asciiartist
99
+ - bin/console
100
+ - bin/setup
101
+ - config/environment.rb
102
+ - gemfile
103
+ - lib/art.rb
104
+ - lib/asciiartist.rb
105
+ - lib/cli.rb
106
+ - lib/scraper.rb
107
+ homepage: ''
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubygems_version: 3.0.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: A nifty CLI that allows users to access ascii art from the command line!
130
+ test_files: []