karenina 0.0.1
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 +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +27 -0
- data/Rakefile +1 -0
- data/karenina.gemspec +24 -0
- data/lib/karenina/book.rb +53 -0
- data/lib/karenina/bookmark.rb +30 -0
- data/lib/karenina/version.rb +3 -0
- data/lib/karenina.rb +17 -0
- data/text/from_project_gutenberg.txt +40291 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NzNjYzA2NTIwZWMxNjJjNjEwNGYzZGFlNDU2ZTkwMDg4MzZiY2YzYw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NTg2YmMyYzIyNzIyYjVkMDcxMGIxMzkzZGJiY2YxNWRlMDhjN2RiMA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NWNkNmQ4Y2RlOGY4ZmEyYmM3ZjQ4YmM5NWE3YTIwNDAwMzZkZjk2ODM4NDlh
|
10
|
+
MmZhYzcyYjBkNDU0ZjEwMzEwYmJmMDM3OWExNjIwZDQ3NjU1YmMyNDY2ODM3
|
11
|
+
MmRiOTJhOTEyZDg1MjZmZjk5NTVjYmI1YWEyZjgyMWVjYjlkZmE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjRlYTA0MjJhZTY3ODczNTIyZWY2ZDBmZjYzNTQxN2MyOTZlZDMxNmQ5MDUz
|
14
|
+
YmNhZjU1YzBhNTc5MWExNGFiNmRmNThlNmJkOTg5OTBhZTc5YmYyMTNkMDZl
|
15
|
+
MWVlNzJkZWMxMTAzYzAzZTc3NzQyNDdhNjMwNDY5MjA0ZTdjYmM=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Graeme Worthy
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Karenina
|
2
|
+
|
3
|
+
If you added up the time you spent waiting for rails to load before you could run your tests, you could have read a russian novel.
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
group :test do
|
12
|
+
gem 'karenina'
|
13
|
+
end
|
14
|
+
|
15
|
+
And this line to your spec/spec_helper, at the top please
|
16
|
+
|
17
|
+
require 'karenina'
|
18
|
+
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install karenina
|
27
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/karenina.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'karenina/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "karenina"
|
8
|
+
spec.version = Karenina::VERSION
|
9
|
+
spec.authors = ["Graeme Worthy"]
|
10
|
+
spec.email = ["graeme@workben.ch"]
|
11
|
+
spec.description = %q{read a line of anna karenina each time you run your tests}
|
12
|
+
spec.summary = %q{read a line of anna karenina each time you run your tests}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency "colored"
|
24
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Karenina
|
2
|
+
class Book
|
3
|
+
|
4
|
+
attr_reader :lines
|
5
|
+
attr_reader :mark
|
6
|
+
|
7
|
+
|
8
|
+
def initialize(context_lines = 5)
|
9
|
+
@context_lines = context_lines
|
10
|
+
file = File.open(Karenina::TEXT_PATH, 'r')
|
11
|
+
@lines = file.readlines
|
12
|
+
@mark = BookMark.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def current_line
|
16
|
+
@lines[@mark.line].to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def current_line_is_blank?
|
20
|
+
current_line =~ /^\s+$/
|
21
|
+
end
|
22
|
+
|
23
|
+
def skip_blank
|
24
|
+
while current_line_is_blank?
|
25
|
+
@mark.increment
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def print()
|
30
|
+
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)
|
38
|
+
else
|
39
|
+
puts text.white
|
40
|
+
end
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def bold_line(text)
|
45
|
+
separator = ""
|
46
|
+
80.times { separator << "-"}
|
47
|
+
puts separator
|
48
|
+
puts text.white.bold
|
49
|
+
puts separator
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Karenina
|
2
|
+
class BookMark
|
3
|
+
|
4
|
+
attr_reader :line
|
5
|
+
attr_reader :filename
|
6
|
+
|
7
|
+
def self.get
|
8
|
+
self.new.line
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@filename = ENV['HOME'] + '/.karenina_bookmark'
|
13
|
+
get_mark
|
14
|
+
increment
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_mark
|
18
|
+
begin
|
19
|
+
File.open(@filename, 'r+') {|f| @line = f.gets.to_i || 0}
|
20
|
+
rescue
|
21
|
+
@line = 0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def increment
|
26
|
+
File.open(@filename, 'w+') {|f| f.puts @line +=1 }
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
data/lib/karenina.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
lib = File.expand_path( File.join(File.dirname(__FILE__), "..", "lib",))
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'karenina/version'
|
5
|
+
require 'karenina/book'
|
6
|
+
require 'karenina/bookmark'
|
7
|
+
require "colored"
|
8
|
+
|
9
|
+
module Karenina
|
10
|
+
TEXT_PATH = File.expand_path( File.join(File.dirname(__FILE__), "..", "text", "from_project_gutenberg.txt",))
|
11
|
+
|
12
|
+
def self.read
|
13
|
+
Book.new.print()
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Karenina.read
|