Rosetta Code/Find bare lang tags: Difference between revisions

→‎{{header|Ruby}}: Added Ruby Header and sample
No edit summary
(→‎{{header|Ruby}}: Added Ruby Header and sample)
Line 383:
</lang>
 
=={{header|Ruby}}==
Quoting from the FAQ: "If you just want the raw wikitext without any other information whatsoever, it's best to use index.php's action=raw mode instead of the API"
<lang Ruby>require "open-uri"
require "cgi"
 
tasks = ["Greatest_common_divisor", "Greatest_element_of_a_list", "Greatest_subsequential_sum"]
part_uri = "http://rosettacode.org/wiki?action=raw&title="
Report = Struct.new(:count, :tasks)
result = Hash.new{|h,k,v| h[k] = Report.new(0, [])}
 
tasks.each do |task|
puts "processing #{task}"
current_lang = "no language"
open(part_uri + CGI.escape(task)).each_line do |line|
current_lang = Regexp.last_match["lang"] if /==\{\{header\|(?<lang>.+)\}\}==/ =~ line
num_no_langs = line.scan(/<lang\s*>/).size
if num_no_langs > 0 then
result[current_lang].count += num_no_langs
result[current_lang].tasks << task
end
end
end
 
puts "\n#{result.values.map(&:count).inject(&:+)} bare language tags.\n\n"
result.each{|k,v| puts "#{v.count} in #{k} (#{v.tasks})"}</lang>
{{Output}}
<pre>
processing Greatest_common_divisor
processing Greatest_element_of_a_list
processing Greatest_subsequential_sum
 
10 bare language tags.
 
2 in Euler Math Toolbox (["Greatest_common_divisor", "Greatest_element_of_a_list"])
1 in gnuplot (["Greatest_common_divisor"])
1 in Bracmat (["Greatest_element_of_a_list"])
2 in МК-61/52 (["Greatest_element_of_a_list", "Greatest_element_of_a_list"])
1 in ooRexx (["Greatest_element_of_a_list"])
2 in Mathprog (["Greatest_subsequential_sum", "Greatest_subsequential_sum"])
1 in PHP (["Greatest_subsequential_sum"])
</pre>
=={{header|Tcl}}==
For all the extra credit (note, takes a substantial amount of time due to number of HTTP requests):
1,149

edits