noter 0.1.0 → 0.2.0
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 +4 -4
- data/bin/noter +46 -5
- data/lib/noter/version.rb +1 -1
- data/lib/noter/viewer.rb +31 -1
- data/noter.gemspec +1 -0
- data/spec/lib/noter/viewer_spec.rb +65 -3
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c87786d868ea352b1cba38c7cc11531c8a438cc8
|
4
|
+
data.tar.gz: 27bc6a124918df8f115aac6ec4dd35669191ae13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e460c85a77f5e210dd9e1b44e85ea61e57dfc00f12955679cfd5de90f15a34d681090afcfd18691996073fa8a02fd4555ae8e0c81fc69c95870e0c79940d31d6
|
7
|
+
data.tar.gz: fa88760035b1659513e3846802b91eac0c80751f87e4cd42f0d0c2abcb3c8f633657a2402967f34acda8e6191c2b9d6aad28ae1a77bd2609000b836a8e89a15a
|
data/bin/noter
CHANGED
@@ -4,22 +4,63 @@ require "noter"
|
|
4
4
|
require "optparse"
|
5
5
|
|
6
6
|
class NoteRunner
|
7
|
+
def initialize
|
8
|
+
@paging = true
|
9
|
+
end
|
10
|
+
|
7
11
|
def run(args)
|
12
|
+
run_parser
|
13
|
+
run_command
|
14
|
+
end
|
15
|
+
|
16
|
+
def run_command
|
17
|
+
case @command
|
18
|
+
when :make_from_file
|
19
|
+
Noter::FileMaker.new.make_from_file(@filename)
|
20
|
+
when :show_first_lines
|
21
|
+
Noter::Viewer.new(:paging => @paging).show_first_lines(:with_filename => @show_names)
|
22
|
+
when :create_from_string
|
23
|
+
Noter::FileMaker.new(@message).save_file
|
24
|
+
when :show_last_n_files
|
25
|
+
Noter::Viewer.new(:paging => @paging).show_last_n_files(@count)
|
26
|
+
when :show_file_from_index
|
27
|
+
Noter::Viewer.new(:paging => @paging).show_file_from_index(@index)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def run_parser
|
8
32
|
parser = OptionParser.new do |opts|
|
9
33
|
opts.on("-f", "--file FILE", "Create a note using the given file") do |filename|
|
10
|
-
|
34
|
+
@command = :make_from_file
|
35
|
+
@filename = filename
|
11
36
|
end
|
12
37
|
|
13
38
|
opts.on("-l", "--one-line", "Show first line of each note file") do
|
14
|
-
|
39
|
+
@command = :show_first_lines
|
15
40
|
end
|
16
41
|
|
17
|
-
opts.on("-n", "--name", "
|
18
|
-
|
42
|
+
opts.on("-n", "--name", "Include names when showing files") do
|
43
|
+
@command = :show_first_lines
|
44
|
+
@show_names = true
|
19
45
|
end
|
20
46
|
|
21
47
|
opts.on("-m", "--message MESSAGE", "Create a note using the given string") do |message|
|
22
|
-
|
48
|
+
@command = :create_from_string
|
49
|
+
@message = message
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on("-t", "--tail COUNT", "the last n files") do |count|
|
53
|
+
@command = :show_last_n_files
|
54
|
+
@count = count
|
55
|
+
end
|
56
|
+
|
57
|
+
opts.on("-s", "--show INDEX", "Show a file with the given index") do |index|
|
58
|
+
@command = :show_file_from_index
|
59
|
+
@index = index
|
60
|
+
end
|
61
|
+
|
62
|
+
opts.on("-u", "--unpaged", "Don't page the output") do |count|
|
63
|
+
@paging = false
|
23
64
|
end
|
24
65
|
end
|
25
66
|
parser.parse!
|
data/lib/noter/version.rb
CHANGED
data/lib/noter/viewer.rb
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
require "noter/note_file"
|
2
|
+
require "pager"
|
2
3
|
|
3
4
|
module Noter
|
4
5
|
class Viewer
|
6
|
+
include Pager
|
7
|
+
|
8
|
+
attr_reader :do_paging
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
@do_paging = options[:paging].nil? ? true : options[:paging]
|
12
|
+
end
|
13
|
+
|
5
14
|
def existing_files
|
6
|
-
Dir.glob("#{NoteFile.dir}/*")
|
15
|
+
@existing_files ||= Dir.glob("#{NoteFile.dir}/*")
|
7
16
|
end
|
8
17
|
|
9
18
|
def show_first_lines(options = {})
|
@@ -16,5 +25,26 @@ module Noter
|
|
16
25
|
puts "#{file.formatted_time}: #{filename_string}#{file.first_line}"
|
17
26
|
end
|
18
27
|
end
|
28
|
+
|
29
|
+
def filename_from_index(index)
|
30
|
+
existing_files[index.to_i]
|
31
|
+
end
|
32
|
+
|
33
|
+
def show_file_from_index(index)
|
34
|
+
show_file(filename_from_index(index))
|
35
|
+
end
|
36
|
+
|
37
|
+
def show_file(filename)
|
38
|
+
contents = File.read(filename)
|
39
|
+
page if @do_paging
|
40
|
+
puts contents
|
41
|
+
end
|
42
|
+
|
43
|
+
def show_last_n_files(num_files)
|
44
|
+
existing_files.last(num_files.to_i).each do |filename|
|
45
|
+
puts "\n\n#{filename}"
|
46
|
+
show_file(filename)
|
47
|
+
end
|
48
|
+
end
|
19
49
|
end
|
20
50
|
end
|
data/noter.gemspec
CHANGED
@@ -5,11 +5,16 @@ require "noter/viewer"
|
|
5
5
|
module Noter
|
6
6
|
describe Viewer do
|
7
7
|
let(:viewer) { Noter::Viewer.new }
|
8
|
+
let(:file_1_name) { "#{NoteFile.dir}/2014_09_21_18_20_22.txt" }
|
9
|
+
let(:file_2_name) { "#{NoteFile.dir}/2014_09_21_19_20_22.txt" }
|
10
|
+
let(:file_1_contents) { "file 1\nline 2" }
|
11
|
+
let(:file_2_contents) { "file 2\nline 2" }
|
8
12
|
|
9
13
|
before do
|
10
14
|
FileUtils.mkdir_p NoteFile.dir
|
11
|
-
File.write(
|
12
|
-
File.write(
|
15
|
+
File.write(file_1_name, file_1_contents)
|
16
|
+
File.write(file_2_name, file_2_contents)
|
17
|
+
allow(viewer).to receive(:puts)
|
13
18
|
end
|
14
19
|
|
15
20
|
describe "#existing_files" do
|
@@ -31,6 +36,63 @@ module Noter
|
|
31
36
|
viewer.show_first_lines(with_filename: true)
|
32
37
|
end
|
33
38
|
end
|
39
|
+
|
40
|
+
describe "#show_file" do
|
41
|
+
it "puts the file" do
|
42
|
+
expect(viewer).to receive(:puts).with(file_1_contents)
|
43
|
+
viewer.show_file(file_1_name)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#show_file_from_index" do
|
48
|
+
it "puts the file" do
|
49
|
+
expect(viewer).to receive(:puts).with(file_1_contents)
|
50
|
+
viewer.show_file_from_index(0)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "when paging is enabled" do
|
55
|
+
let(:viewer) { Noter::Viewer.new({:paging => false}) }
|
56
|
+
|
57
|
+
it "doesn't page" do
|
58
|
+
expect(viewer).to_not receive(:page)
|
59
|
+
viewer.show_file_from_index(0)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "when paging is not enabled" do
|
64
|
+
let(:viewer) { Noter::Viewer.new }
|
65
|
+
|
66
|
+
it "doesn't page" do
|
67
|
+
expect(viewer).to receive(:page)
|
68
|
+
viewer.show_file_from_index(0)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#show_last_n_files" do
|
73
|
+
it "puts the last two files" do
|
74
|
+
expect(viewer).to receive(:puts).with("\n\n#{file_1_name}")
|
75
|
+
expect(viewer).to receive(:puts).with(file_1_contents)
|
76
|
+
expect(viewer).to receive(:puts).with("\n\n#{file_2_name}")
|
77
|
+
expect(viewer).to receive(:puts).with(file_2_contents)
|
78
|
+
viewer.show_last_n_files(2)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "converts string args to int" do
|
82
|
+
expect {
|
83
|
+
viewer.show_last_n_files("2")
|
84
|
+
}.to_not raise_error
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#filename_from_index" do
|
89
|
+
it "returns the filename associated with the index" do
|
90
|
+
expect(viewer.filename_from_index(0)).to eql(file_1_name)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "converts the index from string to int" do
|
94
|
+
expect(viewer.filename_from_index("0")).to eql(file_1_name)
|
95
|
+
end
|
96
|
+
end
|
34
97
|
end
|
35
98
|
end
|
36
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Roush
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0.2'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pager
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.0'
|
111
125
|
description: 'Inspired (read: stolen) from the ''journal'' and ''jrnl'' python progrsm.
|
112
126
|
At the moment, those are more developed; use them instead of this.'
|
113
127
|
email:
|