qv 0.0.5 → 0.1.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/lib/qv/note.rb +22 -4
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d8b7ef1822fa4534a4a959381571012a9b3a8def
|
|
4
|
+
data.tar.gz: 47eaba336bba6cee1e4e71d2f260e980b36fb774
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8533eb5841e1a6a54f922ee9607e3cb77cbe6c1a2ac142a7fd41c1ae16ae6bbc4d970bdb305475ee86be0196a863acd21bf68a93aa7a42c0526c8ca3ab7af98c
|
|
7
|
+
data.tar.gz: 9f219395a3b12c19ac914910f72e256680dd7851692342ad2d617f69628b690701f4642370b93a8b37b7d024804016249371ffd1b1e96b17b4eb27d9115350bf
|
data/lib/qv/note.rb
CHANGED
|
@@ -3,11 +3,17 @@ require 'qv/qvconfig'
|
|
|
3
3
|
class Note
|
|
4
4
|
attr_reader :filename
|
|
5
5
|
|
|
6
|
-
def initialize(args)
|
|
7
|
-
@filename = args[:file]
|
|
6
|
+
def initialize(args = {})
|
|
7
|
+
@filename = validate(args[:file])
|
|
8
8
|
@title = title
|
|
9
9
|
@path = path
|
|
10
10
|
end
|
|
11
|
+
|
|
12
|
+
def validate(filename)
|
|
13
|
+
raise ArgumentError, "Note requires a :file argument" unless filename
|
|
14
|
+
raise ArgumentError, "#{filename} contains an invalid character" unless filename.valid_encoding?
|
|
15
|
+
filename
|
|
16
|
+
end
|
|
11
17
|
|
|
12
18
|
def title
|
|
13
19
|
@title || File.basename(@filename, File.extname(@filename))
|
|
@@ -21,12 +27,24 @@ class Note
|
|
|
21
27
|
File.open(@path)
|
|
22
28
|
end
|
|
23
29
|
|
|
30
|
+
def body
|
|
31
|
+
get_io.read.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
|
|
32
|
+
end
|
|
33
|
+
|
|
24
34
|
def matches?(search_term)
|
|
25
|
-
|
|
35
|
+
begin
|
|
36
|
+
body.match(/^.*#{search_term}.*$/i)
|
|
37
|
+
rescue ArgumentError => e
|
|
38
|
+
raise ArgumentError, "#{filename}: #{e}"
|
|
39
|
+
end
|
|
26
40
|
end
|
|
27
41
|
|
|
28
42
|
def title_matches?(search_term)
|
|
29
|
-
|
|
43
|
+
begin
|
|
44
|
+
title.match(/^.*#{search_term}.*$/i)
|
|
45
|
+
rescue ArgumentError => e
|
|
46
|
+
puts "ERR: Filename of #{@filename}\n#{e}"
|
|
47
|
+
end
|
|
30
48
|
end
|
|
31
49
|
|
|
32
50
|
def edit
|