Class: ReVIEW::Book::Volume
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
-
#chars ⇒ Object
readonly
Returns the value of attribute chars.
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#page_per_kbyte ⇒ Object
Returns the value of attribute page_per_kbyte.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
-
#initialize(bytes = 0, chars = 0, lines = 0) ⇒ Volume
constructor
A new instance of Volume.
- #kbytes ⇒ Object
- #page ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(bytes = 0, chars = 0, lines = 0) ⇒ Volume
Returns a new instance of Volume.
32 33 34 35 36 37 |
# File 'lib/review/book/volume.rb', line 32 def initialize(bytes = 0, chars = 0, lines = 0) @bytes = bytes @chars = chars @lines = lines @page_per_kbyte = nil end |
Instance Attribute Details
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
39 40 41 |
# File 'lib/review/book/volume.rb', line 39 def bytes @bytes end |
#chars ⇒ Object (readonly)
Returns the value of attribute chars.
40 41 42 |
# File 'lib/review/book/volume.rb', line 40 def chars @chars end |
#lines ⇒ Object
Returns the value of attribute lines.
41 42 43 |
# File 'lib/review/book/volume.rb', line 41 def lines @lines end |
#page_per_kbyte ⇒ Object
Returns the value of attribute page_per_kbyte.
42 43 44 |
# File 'lib/review/book/volume.rb', line 42 def page_per_kbyte @page_per_kbyte 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 |
.dummy ⇒ Object
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
56 57 58 59 60 |
# File 'lib/review/book/volume.rb', line 56 def +(other) Volume.new(@bytes + other.bytes, @chars + other.chars, @lines + other.lines) end |
#kbytes ⇒ Object
44 45 46 |
# File 'lib/review/book/volume.rb', line 44 def kbytes (@bytes.to_f / 1024).ceil end |
#page ⇒ Object
48 49 50 |
# File 'lib/review/book/volume.rb', line 48 def page (kbytes.to_f / @page_per_kbyte).ceil end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/review/book/volume.rb', line 52 def to_s "#{kbytes}KB #{@chars}C #{@lines}L #{page}P" end |