Module: Cwc

Defined in:
lib/cwc.rb

Overview

lib/cwc.rb

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.countBytes(file) ⇒ Object



33
34
35
# File 'lib/cwc.rb', line 33

def countBytes(file)
  return File.size(file)
end

.countChars(file) ⇒ Object



42
43
44
# File 'lib/cwc.rb', line 42

def countChars(file)
  return File.read(file).size
end

.countLines(file) ⇒ Object



36
37
38
# File 'lib/cwc.rb', line 36

def countLines(file)
  return File.readlines(file).size
end

.countWords(file) ⇒ Object



39
40
41
# File 'lib/cwc.rb', line 39

def countWords(file)
  return File.read(file).split.size
end

.mainObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cwc.rb', line 46

def main
  o = ""
  file = ARGV[0]
  # if file.length < 1
  #   return parser
  # end

  bytes = countBytes(file)
  words= countWords(file)
  lines= countLines(file)

  if $options.key?(:bytes)
    number = bytes
  end
  if $options.key?(:words)
    number = words
  end
  if $options.key?(:lines)
    number = lines
  end
  if $options.key?(:chars)
    number = countChars(file)
  end

  if $options.length < 1
    o = "\t%d\t%d\t%d\t%s" % [lines, words, bytes, file]
  else
    o = "\t%d\t%s" % [number, file]
  end

  return o
end