Class: Karenina::Book
- Inherits:
-
Object
- Object
- Karenina::Book
- Defined in:
- lib/karenina/book.rb
Instance Attribute Summary collapse
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#mark ⇒ Object
readonly
Returns the value of attribute mark.
Instance Method Summary collapse
- #bold_line(text) ⇒ Object
- #current_line ⇒ Object
- #current_line_is_blank? ⇒ Boolean
-
#initialize(context_lines = 5) ⇒ Book
constructor
A new instance of Book.
- #print ⇒ Object
- #skip_blank ⇒ Object
Constructor Details
Instance Attribute Details
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
4 5 6 |
# File 'lib/karenina/book.rb', line 4 def lines @lines end |
#mark ⇒ Object (readonly)
Returns the value of attribute mark.
5 6 7 |
# File 'lib/karenina/book.rb', line 5 def mark @mark end |
Instance Method Details
#bold_line(text) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/karenina/book.rb', line 44 def bold_line(text) separator = "" 80.times { separator << "-"} puts separator puts text.white.bold puts separator end |
#current_line ⇒ Object
15 16 17 |
# File 'lib/karenina/book.rb', line 15 def current_line @lines[@mark.line].to_s end |
#current_line_is_blank? ⇒ Boolean
19 20 21 |
# File 'lib/karenina/book.rb', line 19 def current_line_is_blank? current_line =~ /^\s+$/ end |
#print ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/karenina/book.rb', line 29 def print() skip_blank current_line = @mark.line first = current_line - @context_lines > 0 ? current_line - @context_lines : 0 last = current_line + @context_lines first.upto(last) {|line| text = lines[line].to_s if line == current_line bold_line(text) else puts text.white end } end |
#skip_blank ⇒ Object
23 24 25 26 27 |
# File 'lib/karenina/book.rb', line 23 def skip_blank while current_line_is_blank? @mark.increment end end |