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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzNjYzA2NTIwZWMxNjJjNjEwNGYzZGFlNDU2ZTkwMDg4MzZiY2YzYw==
4
+ ZTI2YWMzODc3OWI2YjI2MGYxMGY4MjNjNGRiODc2Y2VmYmY0NzEwZg==
5
5
  data.tar.gz: !binary |-
6
- NTg2YmMyYzIyNzIyYjVkMDcxMGIxMzkzZGJiY2YxNWRlMDhjN2RiMA==
6
+ N2YyODExZGFjNTY5ZmQ0ODQ5ZWU1MjhlMzQzY2M5OTk4MThkMjg0ZQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NWNkNmQ4Y2RlOGY4ZmEyYmM3ZjQ4YmM5NWE3YTIwNDAwMzZkZjk2ODM4NDlh
10
- MmZhYzcyYjBkNDU0ZjEwMzEwYmJmMDM3OWExNjIwZDQ3NjU1YmMyNDY2ODM3
11
- MmRiOTJhOTEyZDg1MjZmZjk5NTVjYmI1YWEyZjgyMWVjYjlkZmE=
9
+ M2Y0ZjNlMWFhYWIwYWViZGI5ZTMxZjVkMTc2Y2YxYmM1NTY5ODhiODhmY2I5
10
+ MjBkMTQ0NDBiYTc2ZjkzYjdjNTBmNjQ4YTIxMmMyZjkwM2VmZTFiNDcwNDY0
11
+ ZTg0Y2E1NGY5YTVjMDkwN2YzZTM4MmJhZTExNDMxY2FlMDA3ZjI=
12
12
  data.tar.gz: !binary |-
13
- NjRlYTA0MjJhZTY3ODczNTIyZWY2ZDBmZjYzNTQxN2MyOTZlZDMxNmQ5MDUz
14
- YmNhZjU1YzBhNTc5MWExNGFiNmRmNThlNmJkOTg5OTBhZTc5YmYyMTNkMDZl
15
- MWVlNzJkZWMxMTAzYzAzZTc3NzQyNDdhNjMwNDY5MjA0ZTdjYmM=
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 print()
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
- current_line = @mark.line
32
- first = current_line - @context_lines > 0 ? current_line - @context_lines : 0
33
- last = current_line + @context_lines
34
- first.upto(last) {|line|
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
- puts text.white
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
- puts separator
48
- puts text.white.bold
49
- puts separator
68
+ output << separator
69
+ output << text
70
+ output << separator
71
+ output.join("\n")
50
72
  end
51
73
  end
52
74
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Karenina
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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 "colored"
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.print()
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.1
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-03 00:00:00.000000000 Z
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: ''