buffy 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -1
- data/README.md +1 -1
- data/lib/buffy.rb +41 -6
- data/lib/buffy/version.rb +1 -1
- data/spec/lib/buffy_spec.rb +58 -0
- data/spec/spec_helper.rb +8 -0
- metadata +7 -9
data/Gemfile
CHANGED
data/README.md
CHANGED
data/lib/buffy.rb
CHANGED
@@ -13,18 +13,53 @@ module Buffy
|
|
13
13
|
|
14
14
|
def read_file
|
15
15
|
if File.exists? @filename
|
16
|
-
File.open(@filename, 'rb')
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
file = File.open(@filename, 'rb')
|
17
|
+
@buffer = file.read
|
18
|
+
process_buff
|
19
|
+
return true
|
20
20
|
else
|
21
21
|
@lines = ""
|
22
22
|
@buffer = ""
|
23
|
+
return false
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
27
|
def process_buff
|
27
28
|
@lines = @buffer.split("\n")
|
29
|
+
count_line_zeros
|
28
30
|
end
|
29
|
-
|
30
|
-
|
31
|
+
|
32
|
+
def line(selection, content = "")
|
33
|
+
if content == "" then
|
34
|
+
if selection.is_a?(Range)
|
35
|
+
output = []
|
36
|
+
selection.each do |i|
|
37
|
+
line_no = i
|
38
|
+
formatted_line_no(line_no)
|
39
|
+
output << "#{formatted_line_no(line_no)}#{@lines[line_no-1]}"
|
40
|
+
end
|
41
|
+
output.join("\n")
|
42
|
+
else
|
43
|
+
"#{formatted_line_no(selection)}#{@lines[selection-1]}"
|
44
|
+
end
|
45
|
+
else
|
46
|
+
@lines[selection-1] = content
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def formatted_line_no(line_no)
|
53
|
+
"#{trailing_zeros(line_no, @zeros)}: "
|
54
|
+
end
|
55
|
+
|
56
|
+
def count_line_zeros
|
57
|
+
@zeros = (@lines.length / 10).to_i
|
58
|
+
end
|
59
|
+
|
60
|
+
def trailing_zeros(line_no, zeros)
|
61
|
+
"%#{zeros}d" % line_no
|
62
|
+
end
|
63
|
+
|
64
|
+
end # end FileBuffer
|
65
|
+
end # end buffy
|
data/lib/buffy/version.rb
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Buffy::FileBuffer do
|
4
|
+
before do
|
5
|
+
File.stub(:exists => true, :open => true)
|
6
|
+
@dummy = Buffy::FileBuffer.new("loremipsum.txt")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should have an initializer" do
|
10
|
+
Buffy::FileBuffer.any_instance.should_receive(:read_file).and_return(true)
|
11
|
+
Buffy::FileBuffer.new("filename.txt")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should process buffer" do
|
15
|
+
@dummy.instance_variable_set("@buffer", "hello\nworld")
|
16
|
+
@dummy.process_buff
|
17
|
+
@dummy.lines.should eql ["hello","world"]
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#line" do
|
21
|
+
before do
|
22
|
+
@dummy.instance_variable_set("@buffer", "hello\nworld")
|
23
|
+
@dummy.process_buff
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should show me a line" do
|
27
|
+
@dummy.line(2).should eql "2: world"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should change a line" do
|
31
|
+
@dummy.line(2, "I am a line")
|
32
|
+
@dummy.line(2).should eql "2: I am a line"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should display a range of lines" do
|
36
|
+
multiline = @dummy.line(1..2)
|
37
|
+
multiline.should eql "1: hello\n2: world"
|
38
|
+
end
|
39
|
+
it "should replace multiple lines" do
|
40
|
+
pending "replace a range of lines with a range of lines from input split by newline character"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should colorise" do
|
45
|
+
pending "colorise @buffer and process into individual coloured buffers"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should write back to file" do
|
49
|
+
pending "reopen the file for writing, save the @lines to @buffer and write buffer to file"
|
50
|
+
pending "saving should take a filename as a parameter"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should number the lines" do
|
54
|
+
pending "write the line number to the text representation of a line"
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buffy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-25 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: FileBuffer Gem
|
15
15
|
email:
|
@@ -26,6 +26,8 @@ files:
|
|
26
26
|
- buffy.gemspec
|
27
27
|
- lib/buffy.rb
|
28
28
|
- lib/buffy/version.rb
|
29
|
+
- spec/lib/buffy_spec.rb
|
30
|
+
- spec/spec_helper.rb
|
29
31
|
homepage: https://github.com/jlebrech/buffy
|
30
32
|
licenses: []
|
31
33
|
post_install_message:
|
@@ -38,22 +40,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
40
|
- - ! '>='
|
39
41
|
- !ruby/object:Gem::Version
|
40
42
|
version: '0'
|
41
|
-
segments:
|
42
|
-
- 0
|
43
|
-
hash: 1425776885991693525
|
44
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
44
|
none: false
|
46
45
|
requirements:
|
47
46
|
- - ! '>='
|
48
47
|
- !ruby/object:Gem::Version
|
49
48
|
version: '0'
|
50
|
-
segments:
|
51
|
-
- 0
|
52
|
-
hash: 1425776885991693525
|
53
49
|
requirements: []
|
54
50
|
rubyforge_project:
|
55
51
|
rubygems_version: 1.8.24
|
56
52
|
signing_key:
|
57
53
|
specification_version: 3
|
58
54
|
summary: Loads a file into a file buffer
|
59
|
-
test_files:
|
55
|
+
test_files:
|
56
|
+
- spec/lib/buffy_spec.rb
|
57
|
+
- spec/spec_helper.rb
|