rosettacode 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rosetta.rb +9 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7289a9db8340e11027a32674ebb776cda19ea1a
|
4
|
+
data.tar.gz: 803599866afc90cefd57878ac7301e582c62b02b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c56a002df7457160e50f09c518c1a4bbd11c2554567e646eb8118342478a2a201726f47c1f4315c81f776878c452703f777d1d3f96c67f45ed27f8bc50f3114a
|
7
|
+
data.tar.gz: 9f0c56e337d8d95a256d90888e6e00dac21434674b0a64571a8b1c9837a873066629856ffff6a78610c69df40f05699162cde6fe7aedac69eb76fb1d88be8d5d
|
data/lib/rosetta.rb
CHANGED
@@ -4,8 +4,8 @@ module Lazy
|
|
4
4
|
class Rosetta
|
5
5
|
def self.search(query, lang="ruby")
|
6
6
|
puts "Your language is #{lang}, and your query is #{query}"
|
7
|
-
|
8
|
-
uri = URI("http://rosettacode.org/wiki/" +
|
7
|
+
sanitized_query = query.split(" ").join("_")
|
8
|
+
uri = URI("http://rosettacode.org/wiki/" + sanitized_query)
|
9
9
|
body = Net::HTTP.get(uri)
|
10
10
|
document = Nokogiri::HTML(body)
|
11
11
|
solutions = document.css(".#{lang}")
|
@@ -14,11 +14,13 @@ module Lazy
|
|
14
14
|
open("#{query}.rb", 'a') { |f|
|
15
15
|
simple_solutions.map {|solution| f.puts(solution + "\n\n")}
|
16
16
|
}
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
unless simple_solutions.empty?
|
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
|
+
else
|
21
|
+
puts "Something is wrong with your query. Here's an example: Lazy::Rosetta.search('Fibonacci_sequence', 'javascript')"
|
22
|
+
end
|
20
23
|
end
|
21
24
|
end
|
22
25
|
end
|
23
|
-
|
24
|
-
#example useage: Lazy::Rosetta.search("Fibonacci_sequence", "javascript")
|
26
|
+
Lazy::Rosetta.search('Fibonacci squence', 'javascript')
|