Class: ReVIEW::Book::Volume

Inherits:
Object show all
Defined in:
lib/review/book/volume.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bytes = 0, chars = 0, lines = 0) ⇒ Volume

Returns a new instance of Volume.



32
33
34
35
36
# File 'lib/review/book/volume.rb', line 32

def initialize(bytes = 0, chars = 0, lines = 0)
  @bytes = bytes
  @chars = chars
  @lines = lines
end

Instance Attribute Details

#bytesObject (readonly)

Returns the value of attribute bytes.



38
39
40
# File 'lib/review/book/volume.rb', line 38

def bytes
  @bytes
end

#charsObject (readonly)

Returns the value of attribute chars.



39
40
41
# File 'lib/review/book/volume.rb', line 39

def chars
  @chars
end

#linesObject

Returns the value of attribute lines.



40
41
42
# File 'lib/review/book/volume.rb', line 40

def lines
  @lines
end

Class Method Details

.count_file(path) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/review/book/volume.rb', line 12

def self.count_file(path)
  b = c = l = 0
  File.foreach(path) do |line|
    next if /\A\#@/ =~ line
    text = line.gsub(/\s+/, '')
    b += text.bytesize
    c += text.size
    l += 1
  end
  new(b, c, l)
end

.dummyObject



28
29
30
# File 'lib/review/book/volume.rb', line 28

def self.dummy
  new(-1, -1, -1)
end

.sum(vols) ⇒ Object



24
25
26
# File 'lib/review/book/volume.rb', line 24

def self.sum(vols)
  vols.inject(new) { |sum, i| sum + i }
end

Instance Method Details

#+(other) ⇒ Object



55
56
57
58
59
# File 'lib/review/book/volume.rb', line 55

def +(other)
  Volume.new(@bytes + other.bytes,
             @chars + other.chars,
             @lines + other.lines)
end

#kbytesObject



42
43
44
# File 'lib/review/book/volume.rb', line 42

def kbytes
  (@bytes.to_f / 1024).ceil
end

#pageObject



46
47
48
49
# File 'lib/review/book/volume.rb', line 46

def page
  # XXX:unrelibable
  kbytes.to_f.ceil
end

#to_sObject



51
52
53
# File 'lib/review/book/volume.rb', line 51

def to_s
  "#{kbytes}KB #{@chars}C #{@lines}L #{page}P"
end