class ReVIEW::Book::Volume

Attributes

bytes[R]
chars[R]
lines[RW]
page_per_kbyte[RW]

Public Class Methods

count_file(path) click to toggle source
# File ../../../../../lib/review/book/volume.rb, line 15
def Volume.count_file(path)
  b = c = l = 0
  File.foreach(path) do |line|
    next if %r<\A\#@> =~ line
    text = line.gsub(/\s+/, '')
    b += text.bytesize
    c += text.charsize
    l += 1
  end
  new(b, c, l)
end
dummy() click to toggle source
# File ../../../../../lib/review/book/volume.rb, line 31
def Volume.dummy
  new(-1, -1, -1)
end
new(bytes = 0, chars = 0, lines = 0) click to toggle source
# File ../../../../../lib/review/book/volume.rb, line 35
def initialize(bytes = 0, chars = 0, lines = 0)
  @bytes = bytes
  @chars = chars
  @lines = lines
  @page_per_kbyte = nil
end
sum(vols) click to toggle source
# File ../../../../../lib/review/book/volume.rb, line 27
def Volume.sum(vols)
  vols.inject(new()) {|sum, i| sum + i }
end

Public Instance Methods

+(other) click to toggle source
# File ../../../../../lib/review/book/volume.rb, line 59
def +(other)
  Volume.new(@bytes + other.bytes,
    @chars + other.chars,
    @lines + other.lines)
end
kbytes() click to toggle source
# File ../../../../../lib/review/book/volume.rb, line 47
def kbytes
  (@bytes.to_f / 1024).ceil
end
page() click to toggle source
# File ../../../../../lib/review/book/volume.rb, line 51
def page
  (kbytes.to_f/@page_per_kbyte).ceil
end
to_s() click to toggle source
# File ../../../../../lib/review/book/volume.rb, line 55
def to_s
  "#{kbytes()}KB #{@chars}C #{@lines}L #{page()}P"
end