rosettacode 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/rosetta.rb +24 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4bd2704b7ae8e93b57a6bcf14933c557ee1b7b9a
|
4
|
+
data.tar.gz: bfbebda783e84dad59f69da12178e9fc70a7e01d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6b0c803091532d7aaecc1b5439a944aad3634f5d5114a2a411eefb69de7154f32d78578aad328282c17854c90e7c5c436e852fb3fca881cedb53f821bbcf7f51
|
7
|
+
data.tar.gz: ec7361c9f6d64edc3c78047743ec7cdf53376140c9a61f9bfb4dac8a384afaeb3dabbacbe5af52b8eec08ca0c8046a073991ada210d0d62a9e2e1279089879a2
|
data/lib/rosetta.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'net/http'
|
3
|
+
module Lazy
|
4
|
+
class Rosetta
|
5
|
+
def self.search(query, lang="ruby")
|
6
|
+
puts "Your language is #{lang}, and your query is #{query}"
|
7
|
+
|
8
|
+
uri = URI("http://rosettacode.org/wiki/" + query)
|
9
|
+
body = Net::HTTP.get(uri)
|
10
|
+
document = Nokogiri::HTML(body)
|
11
|
+
solutions = document.css(".#{lang}")
|
12
|
+
simple_solutions = solutions.map {|solution| solution.text.split(" ").join("\n") }
|
13
|
+
|
14
|
+
open("#{query}.rb", 'a') { |f|
|
15
|
+
simple_solutions.map {|solution| f.puts(solution + "\n\n")}
|
16
|
+
}
|
17
|
+
|
18
|
+
puts "A solution for #{query} has been written to #{query}.rb\n\n"
|
19
|
+
puts "Here is the first solution:\n\n #{simple_solutions.first}\n\n"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
#example useage: Lazy::Rosetta.search("Fibonacci_sequence", "javascript")
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rosettacode
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lev Kravinsky
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: kravinskylev@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/rosetta.rb
|
20
|
+
homepage: http://rubygems.org/gems/rosettacode
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.4.6
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: tired of copy and pasting code you've googled? try rosetta
|
44
|
+
test_files: []
|