karenina 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/karenina/book.rb +34 -12
- data/lib/karenina/bookmark.rb +4 -1
- data/lib/karenina/reader.rb +22 -0
- data/lib/karenina/version.rb +1 -1
- data/lib/karenina.rb +5 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTI2YWMzODc3OWI2YjI2MGYxMGY4MjNjNGRiODc2Y2VmYmY0NzEwZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
N2YyODExZGFjNTY5ZmQ0ODQ5ZWU1MjhlMzQzY2M5OTk4MThkMjg0ZQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2Y0ZjNlMWFhYWIwYWViZGI5ZTMxZjVkMTc2Y2YxYmM1NTY5ODhiODhmY2I5
|
10
|
+
MjBkMTQ0NDBiYTc2ZjkzYjdjNTBmNjQ4YTIxMmMyZjkwM2VmZTFiNDcwNDY0
|
11
|
+
ZTg0Y2E1NGY5YTVjMDkwN2YzZTM4MmJhZTExNDMxY2FlMDA3ZjI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NThkZmM3YTU0MWE3MzYwYmZhZmJiYzAwNWFiM2E1YTEyMmRiYzc5NWI3YWFj
|
14
|
+
OGY4OTE2MjNlZTA4YzMxZTA0MmRmNGNkNzFmZjg3YWJmMGI0ZjQxYzc0Zjk1
|
15
|
+
ZGIwNTIxODU3NDE1ZDEyMDcyMjk4ZDA5YzIxMDJlNDQ4M2QxOWM=
|
data/lib/karenina/book.rb
CHANGED
@@ -26,27 +26,49 @@ module Karenina
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
29
|
+
def first_line_num
|
30
|
+
current_line_num - @context_lines > 0 ? current_line_num - @context_lines : 0
|
31
|
+
end
|
32
|
+
|
33
|
+
def last_line_num
|
34
|
+
current_line_num + @context_lines
|
35
|
+
end
|
36
|
+
|
37
|
+
def current_line_num
|
38
|
+
@mark.line
|
39
|
+
end
|
40
|
+
|
41
|
+
def print
|
42
|
+
output = []
|
30
43
|
skip_blank
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
text = lines[line].to_s
|
36
|
-
if line == current_line
|
37
|
-
bold_line(text)
|
44
|
+
first_line_num.upto(last_line_num) {|line|
|
45
|
+
text = @lines[line].to_s.chomp
|
46
|
+
if line == current_line_num
|
47
|
+
output << "#{bold_line(text)}"
|
38
48
|
else
|
39
|
-
|
49
|
+
output << "#{text}"
|
40
50
|
end
|
41
51
|
}
|
52
|
+
output.join("\n") + "\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_str
|
56
|
+
output = []
|
57
|
+
first_line_num.upto(last_line_num) {|line|
|
58
|
+
text = @lines[line].to_s.chomp
|
59
|
+
output << "#{text}"
|
60
|
+
}
|
61
|
+
output.join("\n") + "\n"
|
42
62
|
end
|
43
63
|
|
44
64
|
def bold_line(text)
|
65
|
+
output = []
|
45
66
|
separator = ""
|
46
67
|
80.times { separator << "-"}
|
47
|
-
|
48
|
-
|
49
|
-
|
68
|
+
output << separator
|
69
|
+
output << text
|
70
|
+
output << separator
|
71
|
+
output.join("\n")
|
50
72
|
end
|
51
73
|
end
|
52
74
|
|
data/lib/karenina/bookmark.rb
CHANGED
@@ -11,7 +11,6 @@ module Karenina
|
|
11
11
|
def initialize
|
12
12
|
@filename = ENV['HOME'] + '/.karenina_bookmark'
|
13
13
|
get_mark
|
14
|
-
increment
|
15
14
|
end
|
16
15
|
|
17
16
|
def get_mark
|
@@ -26,5 +25,9 @@ module Karenina
|
|
26
25
|
File.open(@filename, 'w+') {|f| f.puts @line +=1 }
|
27
26
|
end
|
28
27
|
|
28
|
+
def decrement
|
29
|
+
File.open(@filename, 'w+') {|f| f.puts @line -=1 }
|
30
|
+
end
|
31
|
+
|
29
32
|
end
|
30
33
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Karenina
|
2
|
+
class Reader
|
3
|
+
|
4
|
+
attr_reader :book
|
5
|
+
|
6
|
+
def initialize()
|
7
|
+
@book = Book.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def up
|
11
|
+
@book.mark.decrement
|
12
|
+
end
|
13
|
+
|
14
|
+
def down
|
15
|
+
@book.mark.increment
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_str
|
19
|
+
@book.to_str
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/karenina/version.rb
CHANGED
data/lib/karenina.rb
CHANGED
@@ -4,13 +4,16 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'karenina/version'
|
5
5
|
require 'karenina/book'
|
6
6
|
require 'karenina/bookmark'
|
7
|
-
require
|
7
|
+
require 'karenina/reader'
|
8
|
+
#require "colored"
|
8
9
|
|
9
10
|
module Karenina
|
10
11
|
TEXT_PATH = File.expand_path( File.join(File.dirname(__FILE__), "..", "text", "from_project_gutenberg.txt",))
|
11
12
|
|
12
13
|
def self.read
|
13
|
-
Book.new
|
14
|
+
@book = Book.new
|
15
|
+
puts @book.print
|
16
|
+
@book.mark.increment
|
14
17
|
end
|
15
18
|
end
|
16
19
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: karenina
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Graeme Worthy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- lib/karenina.rb
|
69
69
|
- lib/karenina/book.rb
|
70
70
|
- lib/karenina/bookmark.rb
|
71
|
+
- lib/karenina/reader.rb
|
71
72
|
- lib/karenina/version.rb
|
72
73
|
- text/from_project_gutenberg.txt
|
73
74
|
homepage: ''
|