cwc 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/cwc.rb +21 -9
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 26219fa3984acc289fd07a1fd1782558c10d41b36322ddad7cfd920c65fccaa5
|
|
4
|
+
data.tar.gz: a378abedc05d502e2260021dcdd1f4fc3ecbee48ded8ba42f3cb698caf38a827
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: da1347761ea5900388736d931ceee5c251d469d7897b12fa85a032ce28d9ea0269d0c60086a9d5ddadaffc8aa66ba96cd1b092305b38e9627981ba2232493c6e
|
|
7
|
+
data.tar.gz: 62615cc07941dddd78a9107f25b51729d31baf571c7a2f54522562649fba705c91cf4e4bfbfffd4d91ec938e4da54a252677699e2be078ce532748b07bacf612
|
data/lib/cwc.rb
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# lib/cwc.rb
|
|
6
6
|
|
|
7
7
|
module Cwc
|
|
8
|
-
VERSION= "1.
|
|
8
|
+
VERSION= "1.1.0"
|
|
9
9
|
class << self
|
|
10
10
|
require "optparse"
|
|
11
11
|
$options = {}
|
|
@@ -29,6 +29,10 @@ module Cwc
|
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
parser.parse!(into:$options)
|
|
32
|
+
if ARGV.empty? and not STDIN
|
|
33
|
+
puts parser
|
|
34
|
+
exit 1
|
|
35
|
+
end
|
|
32
36
|
|
|
33
37
|
def countBytes(file)
|
|
34
38
|
return File.size(file)
|
|
@@ -45,14 +49,23 @@ module Cwc
|
|
|
45
49
|
|
|
46
50
|
def main
|
|
47
51
|
o = ""
|
|
48
|
-
file = ARGV[0]
|
|
49
|
-
# if file.length < 1
|
|
50
|
-
# return parser
|
|
51
|
-
# end
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
unless ARGV.empty?
|
|
54
|
+
file = ARGV[0]
|
|
55
|
+
else
|
|
56
|
+
file = ""
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
if not STDIN
|
|
60
|
+
bytes = countBytes(file)
|
|
61
|
+
words = countWords(file)
|
|
62
|
+
lines = countLines(file)
|
|
63
|
+
else
|
|
64
|
+
input = STDIN.read
|
|
65
|
+
bytes = input.size
|
|
66
|
+
words = input.split.size
|
|
67
|
+
lines = input.split("\n").size
|
|
68
|
+
end
|
|
56
69
|
|
|
57
70
|
if $options.key?(:bytes)
|
|
58
71
|
number = bytes
|
|
@@ -72,7 +85,6 @@ module Cwc
|
|
|
72
85
|
else
|
|
73
86
|
o = "\t%d\t%s" % [number, file]
|
|
74
87
|
end
|
|
75
|
-
|
|
76
88
|
return o
|
|
77
89
|
end
|
|
78
90
|
end
|