Class: Milkode::InfoPackage
- Inherits:
-
Object
- Object
- Milkode::InfoPackage
- Defined in:
- lib/milkode/cdweb/lib/info_package.rb
Instance Attribute Summary collapse
-
#plang_content ⇒ Object
readonly
Returns the value of attribute plang_content.
-
#summary_content ⇒ Object
readonly
Returns the value of attribute summary_content.
Instance Method Summary collapse
- #breakdown_detail(package_name, records) ⇒ Object
-
#initialize(name, suburl) ⇒ InfoPackage
constructor
A new instance of InfoPackage.
- #lang_to_query(lang) ⇒ Object
- #line_count_total(records) ⇒ Object
- #sorted_plangs(records) ⇒ Object
Constructor Details
#initialize(name, suburl) ⇒ InfoPackage
Returns a new instance of InfoPackage.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/milkode/cdweb/lib/info_package.rb', line 17 def initialize(name, suburl) @suburl = suburl records = Database.instance.package_records(name) # plangs = sorted_plangs(records) @summary_content = <<EOF <table class="table-striped table-bordered table-condensed"> <tr><td>ファイル数</td><td align="right">#{records.size}</td></tr> <tr><td>行数</td><td align="right">#{line_count_total(records)}</td></tr> </table> EOF @plang_content = <<EOF <table class="table-striped table-bordered table-condensed"> #{breakdown_detail(name, records)} </table> EOF end |
Instance Attribute Details
#plang_content ⇒ Object (readonly)
Returns the value of attribute plang_content.
15 16 17 |
# File 'lib/milkode/cdweb/lib/info_package.rb', line 15 def plang_content @plang_content end |
#summary_content ⇒ Object (readonly)
Returns the value of attribute summary_content.
14 15 16 |
# File 'lib/milkode/cdweb/lib/info_package.rb', line 14 def summary_content @summary_content end |
Instance Method Details
#breakdown_detail(package_name, records) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/milkode/cdweb/lib/info_package.rb', line 52 def breakdown_detail(package_name, records) sorted_plangs(records).map {|name, count, lang| percent = (count.to_f / records.size * 100).to_i params = { :query => lang_to_query(lang) } if params[:query] != "" url = @suburl + "/home/" + Mkurl.new(package_name, params).inherit_query_shead "<tr><td>#{name}</td><td align=\"right\"><a href=\"#{url}\">#{count}</a></td><td align=\"right\">#{percent}%</td></tr>" else "<tr><td>#{name}</td><td align=\"right\">#{count}</td><td align=\"right\">#{percent}%</td></tr>" end }.join("\n") end |
#lang_to_query(lang) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/milkode/cdweb/lib/info_package.rb', line 67 def lang_to_query(lang) # @memo # この実装には問題がある。Makefileなどの検索クエリが正しくない。 # 正しく実装するには AND, OR 検索を実装する必要がある result = [] result << lang.suffixs.map{|v|"s:#{v}"}.join(" ") if lang.suffixs result << lang.filenames.map{|v|"f:#{v}"}.join(" ") if lang.filenames result << lang.filepatterns.map{|v|"f:#{v}"}.join(" ") if lang.filepatterns result.join(" ") end |
#line_count_total(records) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/milkode/cdweb/lib/info_package.rb', line 37 def line_count_total(records) records.reduce(0) do |total, record| begin unless record.content.nil? total + record.content.count($/) + 1 else total end rescue ArgumentError # warning_alert("invalid byte sequence : #{record.path}") total end end end |
#sorted_plangs(records) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/milkode/cdweb/lib/info_package.rb', line 78 def sorted_plangs(records) total = {} records.each do |record| lang = PlangDetector.new(record.restpath) if total[lang.name] total[lang.name][0] += 1 else total[lang.name] = [1, lang] end end total.map {|name, data| [name, data[0], data[1]] }.sort {|a, b| if (a[0] == PlangDetector::UNKNOWN) -1 elsif (b[0] == PlangDetector::UNKNOWN) 1 else a[1] <=> b[1] end }.reverse end |