trick_or_treat 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ed86961933ba9a05df61eb97550f1b839d397cd04a64ebcc9b20eefe7ec244ad
4
+ data.tar.gz: 50d25bf88e0dfb2a11b1dee7d3cd1fad963a51fc9125d5d3be5a06a9393528b2
5
+ SHA512:
6
+ metadata.gz: e8348696eceffeb7f59dcdf5af9a4783ef79e2399bfe74b154621a42ae95d2251e5123d1bb3c7d324943e90189a87febcd001ed2e572bd9a841a2bb6dabc3874
7
+ data.tar.gz: 4866e875336fcbc86015344fc778e93045418bc88d0a3e613bb2c58d9a76d03a3b3e0442adedabb252cbbf1f467738e2f502c5d4c25f42e4f9ad2b146791325e
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ TODO.md
10
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in trick_or_treat.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 10.0"
7
+ gem "safe_yaml", "~> 1.0.5"
8
+ gem "nokogiri", "~> 1.10.4"
9
+ gem "pager", "~> 1.0.1"
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ trick_or_treat (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ansi (1.5.0)
10
+ builder (3.2.3)
11
+ byebug (11.0.1)
12
+ mini_portile2 (2.4.0)
13
+ minitest (5.12.2)
14
+ minitest-reporters (1.3.8)
15
+ ansi
16
+ builder
17
+ minitest (>= 5.0)
18
+ ruby-progressbar
19
+ nokogiri (1.10.4)
20
+ mini_portile2 (~> 2.4.0)
21
+ pager (1.0.1)
22
+ rake (10.5.0)
23
+ ruby-progressbar (1.10.1)
24
+ safe_yaml (1.0.5)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 2.0)
31
+ byebug (~> 11.0.1)
32
+ minitest (~> 5.12.0)
33
+ minitest-reporters (~> 1.3.8)
34
+ nokogiri (~> 1.10.4)
35
+ pager (~> 1.0.1)
36
+ rake (~> 10.0)
37
+ safe_yaml (~> 1.0.5)
38
+ trick_or_treat!
39
+
40
+ BUNDLED WITH
41
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 sergioro
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.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ ## TOC<a href="toc"><a>
2
+
3
+ * [Installation](#installation)
4
+ * [Usage](#usage)
5
+ * [Development](#development)
6
+ * [Contributing](#contributing)
7
+ * [License](#license)
8
+ * [References](#references)
9
+
10
+ # TrickOrTreat
11
+
12
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/trick_or_treat`. To experiment with that code, run `bin/console` for an interactive prompt.
13
+
14
+ TODO: Delete this and the text above, and describe your gem
15
+
16
+ ## Installation<a href="installation"><a>
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'trick_or_treat'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install trick_or_treat
31
+
32
+ ## Usage<a href="usage"><a>
33
+
34
+ TODO: Write usage instructions here
35
+
36
+ ## Development<a href="development"><a>
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ 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).
41
+
42
+ ## Contributing<a href="contributing"><a>
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/trick_or_treat.
45
+
46
+ ## License<a href="license"><a>
47
+
48
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
49
+
50
+ ## References<a href="references"><a>
51
+
52
+ 1. [open() returns StringIO instead of Tempfile](https://stackoverflow.com/questions/31527154/rails-open-returns-stringio-instead-of-tempfile/31527533)
53
+ 2. [Remove a node with nokogiri](https://stackoverflow.com/questions/1708504/how-do-i-remove-a-node-with-nokogiri)
54
+ 3. [How to handle 500 erros with openuri?](https://stackoverflow.com/questions/18634684/how-can-i-handle-503-errors-with-open-uri)
55
+ 4. [How do I pick randomly from an array?](https://stackoverflow.com/questions/3482149/how-do-i-pick-randomly-from-an-array)
56
+ 5. [Advantage of tap method in ruby](https://stackoverflow.com/questions/17493080/advantage-of-tap-method-in-ruby)
57
+ 6. []()
58
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "trick_or_treat"
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__)
data/bin/setup ADDED
@@ -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
data/exe/treat ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "trick_or_treat"
4
+
5
+ puts TrickOrTreat.ask ["treat"]
data/exe/trick ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "trick_or_treat"
4
+
5
+ puts TrickOrTreat.ask ["trick"]
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "trick_or_treat"
4
+
5
+ print "Trick or treat? "
6
+
7
+ puts TrickOrTreat.ask [gets.chomp]
@@ -0,0 +1,63 @@
1
+ require "trick_or_treat/version"
2
+ require 'open-uri'
3
+ require 'yaml'
4
+ require 'tempfile'
5
+ require 'nokogiri'
6
+ require 'pager'
7
+
8
+ module TrickOrTreat
9
+ class Error < StandardError; end
10
+
11
+ include Pager
12
+ extend self
13
+
14
+ def ask(args)
15
+ @uri='https://sergioro.mx'
16
+ printf "\e[1;38;05;202mTrick or Treat? "
17
+ return trick if args.delete('trick')
18
+ return treat if args.delete('treat')
19
+ puts "No candy for you"
20
+ end
21
+
22
+ # ensure returned object to be a Tempfile
23
+ def download_to_file(uri, headers={})
24
+ stream = open(uri, "rb", headers)
25
+ return stream if stream.respond_to?(:path)
26
+
27
+ Tempfile.new.tap do |file|
28
+ file.binmode
29
+ IO.copy_stream(stream, file)
30
+ stream.close
31
+ file.rewind
32
+ end
33
+ end
34
+
35
+ def get_links
36
+ @types=['bash', 'vim', 'ruby']
37
+ nodes=Nokogiri::HTML(open(@uri)).css('a')
38
+ nodes.collect{|n| n['href'] if n['href'].match /#{@types.join('|')}/}.compact
39
+ end
40
+
41
+ def trick
42
+ printf "\e[1;38;05;165m Trick\e[0m\n"
43
+ page
44
+ links=get_links
45
+ link=links.sample
46
+ f=open([@uri,link].join('/'))
47
+ content=Nokogiri::HTML(f).css('.post-content')
48
+ content.children[0..1].remove
49
+ content.text
50
+ end
51
+
52
+ def treat
53
+ printf "\e[1;38;05;165m Treat\e[0m\n"
54
+ @treat='quotes.yml'
55
+ headers={}
56
+ headers={'user-agent' => 'treat'}
57
+ treats=YAML.load_file(download_to_file([@uri,@treat].join('/'), headers))
58
+ treats[treats.keys.sample].values.sample
59
+ rescue OpenURI::HTTPError => e
60
+ response=e.io
61
+ response.string
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ module TrickOrTreat
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "trick_or_treat/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "trick_or_treat"
7
+ spec.version = TrickOrTreat::VERSION
8
+ spec.authors = ["Sergio Romero"]
9
+ spec.email = ["sergioro@nmsu.edu"]
10
+
11
+ spec.summary = %q{Trick or treat}
12
+ spec.description = %q{Happy Hackoween}
13
+ spec.homepage = "https://github.com/sergioro9/trick_or_treat"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 2.0"
28
+ spec.add_development_dependency "minitest", "~> 5.12.0"
29
+ spec.add_development_dependency "minitest-reporters", "~> 1.3.8"
30
+ spec.add_development_dependency "byebug", "~> 11.0.1"
31
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trick_or_treat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergio Romero
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-01 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 5.12.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 5.12.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-reporters
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.3.8
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.8
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 11.0.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 11.0.1
69
+ description: Happy Hackoween
70
+ email:
71
+ - sergioro@nmsu.edu
72
+ executables:
73
+ - treat
74
+ - trick
75
+ - trick_or_treat
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - exe/treat
89
+ - exe/trick
90
+ - exe/trick_or_treat
91
+ - lib/trick_or_treat.rb
92
+ - lib/trick_or_treat/version.rb
93
+ - trick_or_treat.gemspec
94
+ homepage: https://github.com/sergioro9/trick_or_treat
95
+ licenses:
96
+ - MIT
97
+ metadata:
98
+ homepage_uri: https://github.com/sergioro9/trick_or_treat
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.0.3
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Trick or treat
118
+ test_files: []