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.
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.
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
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
41 42 43 |
# File 'lib/review/book/volume.rb', line 41 def bytes @bytes end |
#chars ⇒ Object (readonly)
Returns the value of attribute chars.
42 43 44 |
# File 'lib/review/book/volume.rb', line 42 def chars @chars end |
#lines ⇒ Object
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 |
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 |
#kbytes ⇒ Object
45 46 47 |
# File 'lib/review/book/volume.rb', line 45 def kbytes (@bytes.to_f / 1024).ceil end |
#page ⇒ Object
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_s ⇒ Object
53 54 55 |
# File 'lib/review/book/volume.rb', line 53 def to_s "#{kbytes()}KB #{@chars}C #{@lines}L #{page()}P" end |