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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cwc.rb +21 -9
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d721f665f4679032729e440f71f17360d13e5d46eb23a2428964a3bfb134316
4
- data.tar.gz: f4e3bdd1e465807750e0c9e6e8a6c819a0d47894afa5de837a7cf24406e0b840
3
+ metadata.gz: 26219fa3984acc289fd07a1fd1782558c10d41b36322ddad7cfd920c65fccaa5
4
+ data.tar.gz: a378abedc05d502e2260021dcdd1f4fc3ecbee48ded8ba42f3cb698caf38a827
5
5
  SHA512:
6
- metadata.gz: 6b608b23230791cf9222f0df7b18a556d10e9746572e4bf15871143d8fb45773212c0bbf547cb40a39fa5b80bb2e7e9367505c29125942fad48eb9dd8d1ede15
7
- data.tar.gz: ab922b340202d6b93f2f56f95d97990c5ae33ef64f564a36ca6489520e0890f0081b8e732f82a818835a3c3d05d8db2c51083d8a62819be3e0e706d8d5e9c5dd
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.0.0"
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
- bytes = countBytes(file)
54
- words= countWords(file)
55
- lines= countLines(file)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cwc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ceriseris