1 # A generic data object for returning parsing results from Ohcount to Ohloh.
3 # This class has the additional job of declaring a "nice" (human readable) name
4 # for each language, as well as the category (procedural code vs. markup) for each
5 # language. These features should probably live elsewhere, and are currently
6 # not covered by unit tests.
7 class Ohcount::SlocInfo
9 attr_accessor :code_added, :code_removed, :comments_added, :comments_removed, :blanks_added, :blanks_removed
11 def initialize(language)
12 raise ArgumentError.new('language can not be nil') unless language
23 @language == b.language &&
24 @code_added == b.code_added &&
25 @code_removed == b.code_removed &&
26 @comments_added == b.comments_added &&
27 @comments_removed == b.comments_removed &&
28 @blanks_added == b.blanks_added &&
29 @blanks_removed == b.blanks_removed
33 if (@code_added == 0 && @code_removed == 0 &&
34 @comments_added == 0 && @comments_removed == 0 &&
35 @blanks_added == 0 && @blanks_removed == 0)
42 'actionscript' => {:nice_name => 'ActionScript' , :category => 0},
43 'ada' => {:nice_name => 'Ada' , :category => 0},
44 'assembler' => {:nice_name => 'Assembler' , :category => 0},
45 'autoconf' => {:nice_name => 'Autoconf' , :category => 2},
46 'automake' => {:nice_name => 'Automake' , :category => 2},
47 'awk' => {:nice_name => 'AWK' , :category => 0},
48 'bat' => {:nice_name => 'DOS batch script' , :category => 0},
49 'boo' => {:nice_name => 'Boo' , :category => 0},
50 'c' => {:nice_name => 'C' , :category => 0},
51 'classic_basic' => {:nice_name => 'Classic Basic' , :category => 0},
52 'cpp' => {:nice_name => 'C++' , :category => 0},
53 'clearsilver' => {:nice_name => 'ClearSilver' , :category => 0},
54 'csharp' => {:nice_name => 'C#' , :category => 0},
55 'css' => {:nice_name => 'CSS' , :category => 1},
56 'dcl' => {:nice_name => 'DCL' , :category => 0},
57 'dylan' => {:nice_name => 'Dylan' , :category => 0},
58 'ebuild' => {:nice_name => 'Ebuild' , :category => 0},
59 'eiffel' => {:nice_name => 'Eiffel' , :category => 0},
60 'emacslisp' => {:nice_name => 'Emacs Lisp' , :category => 0},
61 'erlang' => {:nice_name => 'Erlang' , :category => 0},
62 'exheres' => {:nice_name => 'Exheres' , :category => 0},
63 'factor' => {:nice_name => 'Factor' , :category => 0},
64 'fortranfixed' => {:nice_name => 'Fortran (Fixed-format)', :category => 0},
65 'fortranfree' => {:nice_name => 'Fortran (Free-format)', :category => 0},
66 'groovy' => {:nice_name => 'Groovy' , :category => 0},
67 'html' => {:nice_name => 'HTML' , :category => 1},
68 'java' => {:nice_name => 'Java' , :category => 0},
69 'javascript' => {:nice_name => 'JavaScript' , :category => 0},
70 'lisp' => {:nice_name => 'Lisp' , :category => 0},
71 'lua' => {:nice_name => 'Lua' , :category => 0},
72 'make' => {:nice_name => 'Make' , :category => 2},
73 'matlab' => {:nice_name => 'Matlab' , :category => 0},
74 'metafont' => {:nice_name => 'MetaFont' , :category => 1},
75 'metapost' => {:nice_name => 'MetaPost' , :category => 1},
76 'mxml' => {:nice_name => 'Flex' , :category => 1},
77 'objective_c' => {:nice_name => 'Objective C' , :category => 0},
78 'ocaml' => {:nice_name => 'Objective Caml' , :category => 0},
79 'pascal' => {:nice_name => 'Pascal' , :category => 0},
80 'perl' => {:nice_name => 'Perl' , :category => 0},
81 'php' => {:nice_name => 'PHP' , :category => 0},
82 'pike' => {:nice_name => 'Pike' , :category => 0},
83 'python' => {:nice_name => 'Python' , :category => 0},
84 'rexx' => {:nice_name => 'rexx' , :category => 0},
85 'ruby' => {:nice_name => 'Ruby' , :category => 0},
86 'scheme' => {:nice_name => 'Scheme' , :category => 0},
87 'scala' => {:nice_name => 'Scala' , :category => 0},
88 'shell' => {:nice_name => 'shell script' , :category => 0},
89 'smalltalk' => {:nice_name => 'Smalltalk' , :category => 0},
90 'structured_basic' => {:nice_name => 'Structured Basic' , :category => 0},
91 'sql' => {:nice_name => 'SQL' , :category => 0},
92 'tcl' => {:nice_name => 'Tcl' , :category => 0},
93 'vala' => {:nice_name => 'Vala' , :category => 0},
94 'vhdl' => {:nice_name => 'VHDL' , :category => 0},
95 'visualbasic' => {:nice_name => 'Visual Basic' , :category => 0},
96 'vim' => {:nice_name => 'Vim Script' , :category => 0},
97 'xml' => {:nice_name => 'XML' , :category => 1},
98 'xmlschema' => {:nice_name => 'XML Schema' , :category => 1},
99 'xslt' => {:nice_name => 'XSL Transformation',:category => 0},
100 'dmd' => {:nice_name => 'D' , :category => 0},
101 'tex' => {:nice_name => 'TeX/LaTeX' , :category => 1},
102 'haskell' => {:nice_name => 'Haskell' , :category => 0}
105 # Returns the human readable name for a language.
106 def language_nice_name
107 @@lang_map[self.language][:nice_name]
110 # Returns the category (procedural code vs. markup) for a language.
112 # Category 0 indicates procedural code (most languages).
113 # Category 1 indicates a markup file, such as XML.
114 # Category 2 indicates a build script, such as make or autoconf
116 # In the Ohloh reports, categories are used only as hints when determining
117 # the "primary" language of an application. Using them, a C application
118 # with a lot of supporting HTML documentation or large autoconf file will
119 # still be successfully identified as a C application.
120 def language_category
121 @@lang_map[self.language][:category]