buffy 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.
data/Gemfile CHANGED
@@ -3,4 +3,6 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in buffy.gemspec
4
4
  gemspec
5
5
 
6
- gem "rake"
6
+ gem 'rake'
7
+ gem 'rspec'
8
+ gem 'pry'
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Buffy
2
2
 
3
- Buffy is a gem for readline files into a buffer
3
+ Buffy is a gem for reading files into a buffer
4
4
 
5
5
  ## Installation
6
6
 
@@ -13,18 +13,53 @@ module Buffy
13
13
 
14
14
  def read_file
15
15
  if File.exists? @filename
16
- File.open(@filename, 'rb') do |f|
17
- @buffer = f.read
18
- process_buff
19
- end
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
- end
30
- end
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
@@ -1,3 +1,3 @@
1
1
  module Buffy
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'buffy'
5
+
6
+ RSpec.configure do |config|
7
+
8
+ end
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.1
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-19 00:00:00.000000000 Z
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