galya 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 739b8f05c62d9c8ed24f8ed390a7da03e7beb979
4
+ data.tar.gz: edf231c07c1931c8a086fa33c505079bb86bd172
5
+ SHA512:
6
+ metadata.gz: e1abce2104cb401ac2a71c5cf841dfd6fe89454aad006041947915871de478fc0cb7165c70321d6f5399a6e641f2e597ccf09d56e264a56e606b8b68bd5e4373
7
+ data.tar.gz: 8746f32377bc4df4345d636e31c886192211f25ff3e8a159f1e55c1363baf19febedf0c608aebbce3e43abbf6ed3f6f8676ea4a57eb1d24bed12e94bcaf0bea4
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in galya.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'rubocop', require: false
8
+ end
9
+
10
+ group :development, :test do
11
+ gem 'rspec'
12
+ end
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Galya
2
+
3
+ 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/galya`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'galya'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install galya
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nu-hin/galya.
36
+
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "galya"
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
data/bin/galya ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'galya'
4
+ require 'cowsay'
5
+
6
+ begin
7
+ msg = Galya.fetch(rand(1..100000)).flatten.join(' ')
8
+
9
+ raise 'Empty' if msg.empty?
10
+
11
+ if ARGV.include? '-c'
12
+ puts Cowsay::Character::Cow.say(msg)
13
+ else
14
+ puts msg
15
+ end
16
+ rescue => ex
17
+ retry
18
+ end
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/galya.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'galya/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'galya'
8
+ spec.version = Galya::VERSION
9
+ spec.authors = ["Nikita Chernukhin"]
10
+ spec.email = ["nuinuhin@gmail.com"]
11
+
12
+ spec.summary = %q{Galya.ru wrapper library and command-line utility}
13
+ spec.description = %q{Get galya.ru quotes from command line or use them in your Ruby project}
14
+ spec.homepage = "https://github.com/Nu-hin/galya"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "bin"
18
+ spec.executables = 'galya'
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'nokogiri'
22
+ spec.add_runtime_dependency 'cowsay'
23
+ end
@@ -0,0 +1,3 @@
1
+ module Galya
2
+ VERSION = "0.1.0"
3
+ end
data/lib/galya.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'galya/version'
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+
5
+ module Galya
6
+ HOST = 'galya.ru'
7
+ PATH = '/clubs/show.php?id=%{id}'
8
+
9
+ def self.fetch(id)
10
+ u = URI.parse(uri(id))
11
+ html = u.read.force_encoding('cp1251').encode('utf-8')
12
+ parsed = Nokogiri::HTML(html)
13
+ parsed.css('.message p').map do |para|
14
+ para.text.lines.map do |line|
15
+ line.strip
16
+ end.reject(&:empty?)
17
+ end
18
+ end
19
+
20
+ def self.path(id)
21
+ PATH % { id: id }
22
+ end
23
+
24
+ def self.uri(id)
25
+ "http://#{HOST}#{path(id)}"
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: galya
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nikita Chernukhin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cowsay
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Get galya.ru quotes from command line or use them in your Ruby project
42
+ email:
43
+ - nuinuhin@gmail.com
44
+ executables:
45
+ - galya
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".travis.yml"
52
+ - Gemfile
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/galya
57
+ - bin/setup
58
+ - galya.gemspec
59
+ - lib/galya.rb
60
+ - lib/galya/version.rb
61
+ homepage: https://github.com/Nu-hin/galya
62
+ licenses: []
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.5.1
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Galya.ru wrapper library and command-line utility
84
+ test_files: []