Write a small script to the latest statistics the number of lines of code to write

class CodeLineStat
        attr_reader :code_lines

        def initialize
                @code_lines = 0
        end

        def stat(path)
                Dir.foreach(path) do |file|
                        if file != "." && file != ".." then
                                filePath = path + "/" + file
                                if File.directory? filePath then
                                        stat(filePath);
                                elsif file =~ /(\.java|\.js|\.jsp)$/ then
                                        @code_lines += file_code_line(filePath);
                                end
                        end
                end
        end

private
        def file_code_line(filePath)
                lines = 0
                File.open(filePath,"r") do |file|
                        in_comment = false;
                        file.each_line do |line|
                                line.strip!
                                if line.index("/*") then
                                        in_comment = true
                                elsif line.index("*/") then
                                        in_comment = false
                                elsif !line.empty? && !in_comment && !line.index("//") then
                                        lines += 1
                                end
                        end
                end
                puts "#{filePath} : #{lines}"
                lines
        end
end

cl = CodeLineStat.new
cl.stat(ARGV[0])
puts cl.code_lines
分类:Ruby 时间:2010-03-27 人气:196
分享到:
blog comments powered by Disqus

相关文章

  • js add a row to delete the line, traversing the table <Reprinted from fly533> 2010-11-06

    js add a row to delete the line, traverse table Article Category: Web front-end / / Requirements: js multi-record update / / 1, A table from the page, select the products to form B, / / 2, Form B, corresponding to each commodity, the number of inputs

  • JSP与JS交互问题 值传递 2014-11-23

    JSP与JS交互问题 值传递 一.在JSP中访问JS返回的值: 问题: <script language="javascript"> <!-- var str="123"; <% String aa; %> --> </script> 怎么让这个JSP里的aa获得JAVASCRIPT中str的值???? 详细一点就是: 复制代码 代码如下: <script language="javascript&qu

  • Js code for the dynamic increase in line 2010-03-11

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- JavaScript Implement dynamic increase. delete form fields --> <HTML> <HEAD> <TITLE> New Document </TITLE> <SCRIPT LANGUAGE="JavaScrip

  • [Change] jsp and online statistics online enrollment 2010-06-21

    First, statistics online 1. Listener Java code package com.logcd.listener; import javax.servlet.ServletContext; import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener; public class SessionCounter implements HttpSess

  • [Original] a simple JSP page JS jump and pass parameters 2011-05-30

    The method is safe, not suitable for large area applications JS in: window.location.href="/getPKTask.jsp?Tmpname=11111"; JSP: String tmpname2 = request.getParameter("Tmpname"); tmpname= "<%=tmpname2%>";

  • 在(ASP/PHP/JSP/html/js)中禁止ajax缓存的方法集锦 2014-06-26

    禁止ajax缓存最简单的办法就是在js端直接生成一个随机数了,但是有时会发现此方法不适用于post了,如果我们要禁止post 提交数据的ajax缓存需要怎么处理呢,下面我整理了很多关于禁止ajax缓存的例子 ajax缓存有好处,但也有坏处,缓存有时候会导致误操作,影响用户体验,若你的WEB项目不需要ajax缓存功能,可按下述方法来禁止ajax缓存. 一.在ASP中禁止ajax缓存: '放在ASP网页最开头部分 Response.expires=0 Response.addHeader("prag

  • jsp项目中更改tomcat的默认index.jsp访问路径的方法 2014-08-10

    如何更改tomcat的默认index.jsp访问路径,jsp的工程下有一个叫做WEB-INF文件夹下的web.xml打开它,按照下面的方法即可修改 jsp的工程下有一个叫做WEB-INF文件夹下的web.xml打开它 如果你要该的默认访问对象再 WebRoot 下面,就 <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> jsp项目默认访问的是inde

  • JSP中js传递和解析URL参数以及中文转码和解码问题 2015-02-01

    有关js传递和解析URL参数以及中文转码和解码问题,都是在js中很常见的,下面通过示例简单为大家介绍下,感兴趣的朋友可以参考下 1.传递参数: var pmt = 'sensor='+ encodeURI(encodeURI(sensor))+'&device='+encodeURI(encodeURI(device))+'&instrument='; pmt += encodeURI(encodeURI(instrument))+'&n='+n+'&addDate='+a

  • jsp and js are two ways to get to the form data 2010-05-13

    <form action="" method="post" onsubmit="return check()" name="selectform"> <input type="radio" name="gender" value="man" checked/> Male <input type="radio" name

  • Enter the characters in length JS statistics (including full-width. Chinese and half-width) 2011-05-17

    function getStringLength (str) { var totalLength = 0; var list = str.split (""); for (var i = 0; i <list.length; i + +) { var s = list [i]; if (s.match (/ [\ u0000-\ u00ff] / g)) {/ / half-width totalLength + = 1; } Else if (s.match (/ [\ u4e

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.169 (s). 12 q(s)