Class: Karenina::BookMark

Inherits:
Object
  • Object
show all
Defined in:
lib/karenina/bookmark.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBookMark

Returns a new instance of BookMark.



11
12
13
14
# File 'lib/karenina/bookmark.rb', line 11

def initialize
  @filename = ENV['HOME'] + '/.karenina_bookmark'
  get_mark
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/karenina/bookmark.rb', line 5

def filename
  @filename
end

#lineObject (readonly)

Returns the value of attribute line.



4
5
6
# File 'lib/karenina/bookmark.rb', line 4

def line
  @line
end

Class Method Details

.getObject



7
8
9
# File 'lib/karenina/bookmark.rb', line 7

def self.get
  self.new.line
end

Instance Method Details

#decrementObject



28
29
30
# File 'lib/karenina/bookmark.rb', line 28

def decrement
  File.open(@filename, 'w+') {|f| f.puts @line -=1 }
end

#get_markObject



16
17
18
19
20
21
22
# File 'lib/karenina/bookmark.rb', line 16

def get_mark
  begin
     File.open(@filename, 'r+') {|f| @line = f.gets.to_i || 0}
  rescue
     @line = 0
  end
end

#incrementObject



24
25
26
# File 'lib/karenina/bookmark.rb', line 24

def increment
  File.open(@filename, 'w+') {|f| f.puts @line +=1 }
end