wc 0.98.2 → 0.99.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,208 @@
1
+
2
+ body {
3
+ font-family: Verdana,Arial,Helvetica,sans-serif;
4
+ font-size: 90%;
5
+ margin: 0;
6
+ margin-left: 40px;
7
+ padding: 0;
8
+ background: white;
9
+ }
10
+
11
+ h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
12
+ h1 { font-size: 150%; }
13
+ h2,h3,h4 { margin-top: 1em; }
14
+
15
+ a { background: #eef; color: #039; text-decoration: none; }
16
+ a:hover { background: #039; color: #eef; }
17
+
18
+ /* Override the base stylesheet's Anchor inside a table cell */
19
+ td > a {
20
+ background: transparent;
21
+ color: #039;
22
+ text-decoration: none;
23
+ }
24
+
25
+ /* and inside a section title */
26
+ .section-title > a {
27
+ background: transparent;
28
+ color: #eee;
29
+ text-decoration: none;
30
+ }
31
+
32
+ /* === Structural elements =================================== */
33
+
34
+ div#index {
35
+ margin: 0;
36
+ margin-left: -40px;
37
+ padding: 0;
38
+ font-size: 90%;
39
+ }
40
+
41
+
42
+ div#index a {
43
+ margin-left: 0.7em;
44
+ }
45
+
46
+ div#index .section-bar {
47
+ margin-left: 0px;
48
+ padding-left: 0.7em;
49
+ background: #ccc;
50
+ font-size: small;
51
+ }
52
+
53
+
54
+ div#classHeader, div#fileHeader {
55
+ width: auto;
56
+ color: white;
57
+ padding: 0.5em 1.5em 0.5em 1.5em;
58
+ margin: 0;
59
+ margin-left: -40px;
60
+ border-bottom: 3px solid #006;
61
+ }
62
+
63
+ div#classHeader a, div#fileHeader a {
64
+ background: inherit;
65
+ color: white;
66
+ }
67
+
68
+ div#classHeader td, div#fileHeader td {
69
+ background: inherit;
70
+ color: white;
71
+ }
72
+
73
+
74
+ div#fileHeader {
75
+ background: #057;
76
+ }
77
+
78
+ div#classHeader {
79
+ background: #048;
80
+ }
81
+
82
+
83
+ .class-name-in-header {
84
+ font-size: 180%;
85
+ font-weight: bold;
86
+ }
87
+
88
+
89
+ div#bodyContent {
90
+ padding: 0 1.5em 0 1.5em;
91
+ }
92
+
93
+ div#description {
94
+ padding: 0.5em 1.5em;
95
+ background: #efefef;
96
+ border: 1px dotted #999;
97
+ }
98
+
99
+ div#description h1,h2,h3,h4,h5,h6 {
100
+ color: #125;;
101
+ background: transparent;
102
+ }
103
+
104
+ div#validator-badges {
105
+ text-align: center;
106
+ }
107
+ div#validator-badges img { border: 0; }
108
+
109
+ div#copyright {
110
+ color: #333;
111
+ background: #efefef;
112
+ font: 0.75em sans-serif;
113
+ margin-top: 5em;
114
+ margin-bottom: 0;
115
+ padding: 0.5em 2em;
116
+ }
117
+
118
+
119
+ /* === Classes =================================== */
120
+
121
+ table.header-table {
122
+ color: white;
123
+ font-size: small;
124
+ }
125
+
126
+ .type-note {
127
+ font-size: small;
128
+ color: #DEDEDE;
129
+ }
130
+
131
+ .xxsection-bar {
132
+ background: #eee;
133
+ color: #333;
134
+ padding: 3px;
135
+ }
136
+
137
+ .section-bar {
138
+ color: #333;
139
+ border-bottom: 1px solid #999;
140
+ margin-left: -20px;
141
+ }
142
+
143
+
144
+ .section-title {
145
+ background: #79a;
146
+ color: #eee;
147
+ padding: 3px;
148
+ margin-top: 2em;
149
+ margin-left: -30px;
150
+ border: 1px solid #999;
151
+ }
152
+
153
+ .top-aligned-row { vertical-align: top }
154
+ .bottom-aligned-row { vertical-align: bottom }
155
+
156
+ /* --- Context section classes ----------------------- */
157
+
158
+ .context-row { }
159
+ .context-item-name { font-family: monospace; font-weight: bold; color: black; }
160
+ .context-item-value { font-size: small; color: #448; }
161
+ .context-item-desc { color: #333; padding-left: 2em; }
162
+
163
+ /* --- Method classes -------------------------- */
164
+ .method-detail {
165
+ background: #efefef;
166
+ padding: 0;
167
+ margin-top: 0.5em;
168
+ margin-bottom: 1em;
169
+ border: 1px dotted #ccc;
170
+ }
171
+ .method-heading {
172
+ color: black;
173
+ background: #ccc;
174
+ border-bottom: 1px solid #666;
175
+ padding: 0.2em 0.5em 0 0.5em;
176
+ }
177
+ .method-signature { color: black; background: inherit; }
178
+ .method-name { font-weight: bold; }
179
+ .method-args { font-style: italic; }
180
+ .method-description { padding: 0 0.5em 0 0.5em; }
181
+
182
+ /* --- Source code sections -------------------- */
183
+
184
+ a.source-toggle { font-size: 90%; }
185
+ div.method-source-code {
186
+ background: #262626;
187
+ color: #ffdead;
188
+ margin: 1em;
189
+ padding: 0.5em;
190
+ border: 1px dashed #999;
191
+ overflow: hidden;
192
+ }
193
+
194
+ div.method-source-code pre { color: #ffdead; overflow: hidden; }
195
+
196
+ /* --- Ruby keyword styles --------------------- */
197
+
198
+ .standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
199
+
200
+ .ruby-constant { color: #7fffd4; background: transparent; }
201
+ .ruby-keyword { color: #00ffff; background: transparent; }
202
+ .ruby-ivar { color: #eedd82; background: transparent; }
203
+ .ruby-operator { color: #00ffee; background: transparent; }
204
+ .ruby-identifier { color: #ffdead; background: transparent; }
205
+ .ruby-node { color: #ffa07a; background: transparent; }
206
+ .ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
207
+ .ruby-regexp { color: #ffa07a; background: transparent; }
208
+ .ruby-value { color: #7fffd4; background: transparent; }
@@ -0,0 +1,90 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>Top Level Namespace</title>
7
+ <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
8
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
9
+
10
+ <script type="text/javascript" charset="utf-8">
11
+ relpath = '';
12
+ if (relpath != '') relpath += '/';
13
+ </script>
14
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
15
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
16
+
17
+ </head>
18
+ <body>
19
+ <script type="text/javascript" charset="utf-8">
20
+ if (window.top.frames.main) document.body.className = 'frames';
21
+ </script>
22
+
23
+ <div id="header">
24
+ <div id="menu">
25
+
26
+ <a href="_index.html">Index</a> &raquo;
27
+
28
+
29
+ <span class="title">Top Level Namespace</span>
30
+
31
+
32
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
33
+ </div>
34
+
35
+ <div id="search">
36
+ <a id="class_list_link" href="#">Class List</a>
37
+ <a id="method_list_link" href="#">Method List</a>
38
+ <a id ="file_list_link" href="#">File List</a>
39
+ </div>
40
+
41
+ <div class="clear"></div>
42
+ </div>
43
+
44
+ <iframe id="search_frame"></iframe>
45
+
46
+ <div id="content"><h1>Top Level Namespace
47
+
48
+
49
+
50
+ </h1>
51
+
52
+ <dl class="box">
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+ </dl>
62
+ <div class="clear"></div>
63
+
64
+ <h2>Defined Under Namespace</h2>
65
+ <p class="children">
66
+
67
+
68
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="Wc.html" title="Wc (module)">Wc</a></span>
69
+
70
+
71
+
72
+ <strong class="classes">Classes:</strong> <span class='object_link'><a href="String.html" title="String (class)">String</a></span>
73
+
74
+
75
+ </p>
76
+
77
+
78
+
79
+
80
+
81
+ </div>
82
+
83
+ <div id="footer">
84
+ Generated on Tue Jul 5 09:22:52 2011 by
85
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
86
+ 0.6.8 (ruby-1.9.2).
87
+ </div>
88
+
89
+ </body>
90
+ </html>
data/lib/wc.rb CHANGED
@@ -1,66 +1,27 @@
1
- class Wc
2
- attr_reader :filename, :occurrences, :words, :no_autorun, :css, :css_mode
3
- attr_accessor :hide_list
4
-
5
- # Creates a new Wc object
6
- #
7
- # The filename is no mandatory, but if provided it will be used to feed thw
8
- # word counter gem, otherwise standard input is used.
9
- # Options is an array customizing the gem's behavior further.
10
- #
11
-
12
- def initialize(filename=nil, options={})
13
- @hide_list = options["hide_list"]
14
- @words = options["words"]
15
- @no_autorun = options["no_autorun"]
16
-
17
- @css_mode = options["css_mode"]
18
-
19
- if ! @hide_list
20
- @hide_list = []
21
- end
22
-
23
- if ! @no_autorun
24
- warn "[DEPRECATION]: 'no_autorun' option will be deprecated in wc 1.0.0 and the default behavior will be no_autorun=TRUE"
25
- if filename
26
- @filename = filename
27
- @occurrences = _read
28
- else
29
- @filename =STDIN
30
- @occurrences = _feed
31
- end
32
- @sorted = Array(occurrences).sort { |one, two| -(one[1] <=> two[1]) }
33
- end
1
+ require 'wc/engine'
2
+
3
+ class String
4
+
5
+ def wc
6
+ self.occurrences.size
34
7
  end
35
-
36
- def to_text
37
- if @words == -1
38
- @sorted.each { |elem|
39
- puts "\"#{elem[0]}\" has #{elem[1]} occurrences"
40
- }
41
- else
42
- @sorted[0..@words-1].each { |elem|
43
- puts "\"#{elem[0]}\" has #{elem[1]} occurrences"
44
- }
45
- end
8
+
9
+ def occurrences
10
+ Wc::Engine.read_inline(self)
46
11
  end
47
-
48
- # def to_json
49
- # if @words == -1
50
- # return @sorted.to_json
51
- # else
52
- # return @sorted[0..@words-1].to_json
53
- # end
54
- # end
55
-
56
- def to_cloud
57
- if @words == -1
58
- cloud_items = @sorted
12
+
13
+ def to_tag_cloud(max_words = nil)
14
+
15
+ sorted = self.occurrences
16
+
17
+ if max_words.nil?
18
+ cloud_items = sorted
59
19
  else
60
- cloud_items = @sorted[0..@words-1]
20
+ cloud_items = sorted[0..max_words-1]
61
21
  end
62
- max = @sorted.first[1]
63
- min = @sorted.last[1]
22
+
23
+ max = sorted.first[1]
24
+ min = sorted.last[1]
64
25
 
65
26
  range = max - min
66
27
  interval = (1.0 * range)/10
@@ -109,72 +70,4 @@ class Wc
109
70
  ret
110
71
  end
111
72
 
112
- def read(filename)
113
- @occurrences = Hash.new { |h, k| h[k] = 0 }
114
- File.open(filename, "r") { |f|
115
- f.each_line { |line|
116
- words = line.split
117
- words.each { |w|
118
- if ! hide_list.include?(w.downcase)
119
- @occurrences[w.downcase] += 1
120
- end
121
- }
122
- }
123
- }
124
- @occurrences
125
- end
126
-
127
- def feed(line)
128
- @occurrences = Hash.new { |h, k| h[k] = 0 }
129
- words = line.split
130
- words.each { |w|
131
- if ! hide_list.include?(w.downcase)
132
- @occurrences[w.downcase] += 1
133
- end
134
- }
135
- @occurrences
136
- end
137
-
138
- def get()
139
- @sorted = Array(occurrences).sort { |one, two| -(one[1] <=> two[1]) }
140
- if @words == -1
141
- c = @sorted
142
- else
143
- c = @sorted[0..@words-1]
144
- end
145
- @sorted = c
146
- end
147
-
148
- private
149
-
150
- def _read()
151
- occurrences = Hash.new { |h, k| h[k] = 0 }
152
- File.open(@filename, "r") { |f|
153
- f.each_line { |line|
154
- words = line.split
155
- words.each { |w|
156
- if ! hide_list.include?(w.downcase)
157
- occurrences[w.downcase] += 1
158
- end
159
- }
160
- }
161
- }
162
- occurrences
163
- end
164
-
165
- def _feed()
166
- occurrences = Hash.new { |h, k| h[k] = 0 }
167
- filename.each_line { |line|
168
- words = line.split
169
- words.each { |w|
170
- if ! hide_list.include?(w.downcase)
171
- occurrences[w.downcase] += 1
172
- end
173
- }
174
- }
175
- occurrences
176
- end
177
-
178
-
179
-
180
- end
73
+ end