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.



35
36
37
38
39
# File 'lib/review/book/volume.rb', line 35

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.



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

def bytes
  @bytes
end

#charsObject (readonly)

Returns the value of attribute chars.



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

def chars
  @chars
end

#linesObject

Returns the value of attribute lines.



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

def lines
  @lines
end

Class Method Details

.count_file(path) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# 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

.dummyObject



31
32
33
# File 'lib/review/book/volume.rb', line 31

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

.sum(vols) ⇒ Object



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

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

Instance Method Details

#+(other) ⇒ Object



57
58
59
60
61
# File 'lib/review/book/volume.rb', line 57

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

#kbytesObject



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

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

#pageObject



49
50
51
# File 'lib/review/book/volume.rb', line 49

def page
  (kbytes.to_f/ReVIEW.book.page_metric.page_per_kbyte).ceil
end

#to_sObject



53
54
55
# File 'lib/review/book/volume.rb', line 53

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