textrepo 0.4.3 → 0.4.4
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/Rakefile +0 -1
- data/lib/textrepo/file_system_repository.rb +16 -13
- data/lib/textrepo/repository.rb +8 -8
- data/lib/textrepo/timestamp.rb +48 -16
- data/lib/textrepo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7415dcbc8ec9483a33c0027432a60473fd0b77ad67369b25b88fb0f399edd788
|
4
|
+
data.tar.gz: 9467336f5d93ec578d5693005a4737f4eef55aeb11e4c0a4ec12f197e81de240
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f989032a0f1db66aeb1392cf9b05fd89306152d1b76907953c90ec14839d7a34465a017a2be8017536270b9a071cd3027497305978fdf59681d3547c8a68a5e5
|
7
|
+
data.tar.gz: cfb126c03ce9720dd2f2e90453a5d2baf33160c7786a8a1d9b5ef02b2c4a4e2531de5744d255efd7979a39e87c9e93287de3397533404143b51be1eb8bb23a58
|
data/Rakefile
CHANGED
@@ -47,6 +47,9 @@ module Textrepo
|
|
47
47
|
#
|
48
48
|
# Default values are set when `repository_name` and `default_extname`
|
49
49
|
# were not defined in `conf`.
|
50
|
+
#
|
51
|
+
# :call-seq:
|
52
|
+
# new(Rbnotes::Conf or Hash) -> FileSystemRepository
|
50
53
|
|
51
54
|
def initialize(conf)
|
52
55
|
super
|
@@ -60,9 +63,9 @@ module Textrepo
|
|
60
63
|
##
|
61
64
|
# Creates a file into the repository, which contains the specified
|
62
65
|
# text and is associated to the timestamp.
|
63
|
-
|
66
|
+
#
|
64
67
|
# :call-seq:
|
65
|
-
# create(Timestamp, Array)
|
68
|
+
# create(Timestamp, Array) -> Timestamp
|
66
69
|
|
67
70
|
def create(timestamp, text)
|
68
71
|
abs = abspath(timestamp)
|
@@ -76,9 +79,9 @@ module Textrepo
|
|
76
79
|
##
|
77
80
|
# Reads the file content in the repository. Then, returns its
|
78
81
|
# content.
|
79
|
-
|
82
|
+
#
|
80
83
|
# :call-seq:
|
81
|
-
# read(Timestamp)
|
84
|
+
# read(Timestamp) -> Array
|
82
85
|
|
83
86
|
def read(timestamp)
|
84
87
|
abs = abspath(timestamp)
|
@@ -93,9 +96,9 @@ module Textrepo
|
|
93
96
|
##
|
94
97
|
# Updates the file content in the repository. A new timestamp
|
95
98
|
# will be attached to the text.
|
96
|
-
|
99
|
+
#
|
97
100
|
# :call-seq:
|
98
|
-
# update(Timestamp, Array)
|
101
|
+
# update(Timestamp, Array) -> Timestamp
|
99
102
|
|
100
103
|
def update(timestamp, text)
|
101
104
|
raise EmptyTextError if text.empty?
|
@@ -115,9 +118,9 @@ module Textrepo
|
|
115
118
|
|
116
119
|
##
|
117
120
|
# Deletes the file in the repository.
|
118
|
-
|
121
|
+
#
|
119
122
|
# :call-seq:
|
120
|
-
# delete(Timestamp)
|
123
|
+
# delete(Timestamp) -> Array
|
121
124
|
|
122
125
|
def delete(timestamp)
|
123
126
|
abs = abspath(timestamp)
|
@@ -131,9 +134,9 @@ module Textrepo
|
|
131
134
|
|
132
135
|
##
|
133
136
|
# Finds entries of text those timestamp matches the specified pattern.
|
134
|
-
|
137
|
+
#
|
135
138
|
# :call-seq:
|
136
|
-
# entries(String = nil)
|
139
|
+
# entries(String = nil) -> Array of Timestamp instances
|
137
140
|
|
138
141
|
def entries(stamp_pattern = nil)
|
139
142
|
results = []
|
@@ -142,7 +145,7 @@ module Textrepo
|
|
142
145
|
when "yyyymoddhhmiss_lll".size
|
143
146
|
stamp = Timestamp.parse_s(stamp_pattern)
|
144
147
|
if exist?(stamp)
|
145
|
-
results << stamp
|
148
|
+
results << stamp
|
146
149
|
end
|
147
150
|
when 0, "yyyymoddhhmiss".size, "yyyymodd".size
|
148
151
|
results += find_entries(stamp_pattern)
|
@@ -168,7 +171,7 @@ module Textrepo
|
|
168
171
|
##
|
169
172
|
# Check the existence of text which is associated with the given
|
170
173
|
# timestamp.
|
171
|
-
|
174
|
+
#
|
172
175
|
# :call-seq:
|
173
176
|
# exist?(Timestamp) -> true or false
|
174
177
|
|
@@ -205,7 +208,7 @@ module Textrepo
|
|
205
208
|
|
206
209
|
def find_entries(stamp_pattern)
|
207
210
|
Dir.glob("#{@path}/**/#{stamp_pattern}*.#{@extname}").map { |e|
|
208
|
-
timestamp_str(e)
|
211
|
+
Timestamp.parse_s(timestamp_str(e))
|
209
212
|
}
|
210
213
|
end
|
211
214
|
|
data/lib/textrepo/repository.rb
CHANGED
@@ -27,7 +27,7 @@ module Textrepo
|
|
27
27
|
##
|
28
28
|
# Stores text data into the repository with the specified timestamp.
|
29
29
|
# Returns the timestamp.
|
30
|
-
|
30
|
+
#
|
31
31
|
# :call-seq:
|
32
32
|
# create(Timestamp, Array) -> Timestamp
|
33
33
|
|
@@ -36,7 +36,7 @@ module Textrepo
|
|
36
36
|
##
|
37
37
|
# Reads text data from the repository, which is associated to the
|
38
38
|
# timestamp. Returns an array which contains the text.
|
39
|
-
|
39
|
+
#
|
40
40
|
# :call-seq:
|
41
41
|
# read(Timestamp) -> Array
|
42
42
|
|
@@ -45,7 +45,7 @@ module Textrepo
|
|
45
45
|
##
|
46
46
|
# Updates the content with text in the repository, which is
|
47
47
|
# associated to the timestamp. Returns the timestamp.
|
48
|
-
|
48
|
+
#
|
49
49
|
# :call-seq:
|
50
50
|
# update(Timestamp, Array) -> Timestamp
|
51
51
|
|
@@ -54,7 +54,7 @@ module Textrepo
|
|
54
54
|
##
|
55
55
|
# Deletes the content in the repository, which is associated to
|
56
56
|
# the timestamp. Returns an array which contains the deleted text.
|
57
|
-
|
57
|
+
#
|
58
58
|
# :call-seq:
|
59
59
|
# delete(Timestamp) -> Array
|
60
60
|
|
@@ -63,8 +63,8 @@ module Textrepo
|
|
63
63
|
##
|
64
64
|
# Finds all entries of text those have timestamps which mathes the
|
65
65
|
# specified pattern of timestamp. Returns an array which contains
|
66
|
-
#
|
67
|
-
# returned.
|
66
|
+
# instances of Timestamp. If none of text was found, an empty
|
67
|
+
# array would be returned.
|
68
68
|
#
|
69
69
|
# A pattern must be one of the following:
|
70
70
|
#
|
@@ -78,9 +78,9 @@ module Textrepo
|
|
78
78
|
# If `stamp_pattern` is omitted, the recent entries will be listed.
|
79
79
|
# Then, how many entries are listed depends on the implementaiton
|
80
80
|
# of the concrete repository class.
|
81
|
-
|
81
|
+
#
|
82
82
|
# :call-seq:
|
83
|
-
# entries(String) -> Array
|
83
|
+
# entries(String) -> Array of Timestamp instances
|
84
84
|
|
85
85
|
def entries(stamp_pattern = nil); []; end
|
86
86
|
|
data/lib/textrepo/timestamp.rb
CHANGED
@@ -1,23 +1,47 @@
|
|
1
1
|
module Textrepo
|
2
2
|
##
|
3
|
-
#
|
3
|
+
# Timestamp is generated from a Time object. It converts a time to
|
4
4
|
# string in the obvious format, such "20201023122400".
|
5
5
|
#
|
6
|
+
# Since the obvious format contains only year, month, day, hour,
|
7
|
+
# minute, and second, the resolution of time is a second. That is,
|
8
|
+
# two Time object those are different only in second will generates
|
9
|
+
# equal Timestamp objects.
|
10
|
+
#
|
11
|
+
# If a client program of Textrepo::Timestamp wants to distinguish
|
12
|
+
# those Time objects, an attribute `suffix` could be used.
|
13
|
+
#
|
14
|
+
# For example, the `suffix` will be converted into a 3 character
|
15
|
+
# string, such "012", "345", "678", ... etc. So, millisecond part
|
16
|
+
# of a Time object will be suitable to pass as `suffix` when
|
17
|
+
# creating a Timestamp object.
|
18
|
+
|
6
19
|
class Timestamp
|
7
20
|
include Comparable
|
8
21
|
|
9
|
-
|
22
|
+
##
|
23
|
+
# Time object which generates the Timestamp object.
|
24
|
+
|
25
|
+
attr_reader :time
|
10
26
|
|
11
27
|
##
|
12
|
-
#
|
13
|
-
|
28
|
+
# An integer specified in `new` method to create the Timestamp object.
|
29
|
+
|
30
|
+
attr_reader :suffix
|
31
|
+
|
32
|
+
##
|
33
|
+
# Creates a Timestamp object from a Time object. In addition, an
|
34
|
+
# Integer can be passed as a suffix use.
|
14
35
|
#
|
36
|
+
# :call-seq:
|
37
|
+
# new(Time, Integer = nil) -> Timestamp
|
38
|
+
|
15
39
|
def initialize(time, suffix = nil)
|
16
40
|
@time = time
|
17
41
|
@suffix = suffix
|
18
42
|
end
|
19
43
|
|
20
|
-
def <=>(other)
|
44
|
+
def <=>(other) # :nodoc:
|
21
45
|
result = (self.time <=> other.time)
|
22
46
|
|
23
47
|
sfx = self.suffix || 0
|
@@ -29,12 +53,10 @@ module Textrepo
|
|
29
53
|
##
|
30
54
|
# Generate an obvious time string.
|
31
55
|
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
|
36
|
-
# ```
|
37
|
-
#
|
56
|
+
# %Y %m %d %H %M %S suffix
|
57
|
+
# "2020-12-30 12:34:56 (0 | nil)" -> "20201230123456"
|
58
|
+
# "2020-12-30 12:34:56 (7)" -> "20201230123456_007"
|
59
|
+
|
38
60
|
def to_s
|
39
61
|
s = @time.strftime("%Y%m%d%H%M%S")
|
40
62
|
s += "_#{"%03u" % @suffix}" unless @suffix.nil? || @suffix == 0
|
@@ -43,18 +65,28 @@ module Textrepo
|
|
43
65
|
|
44
66
|
class << self
|
45
67
|
##
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
# "20201230123456_789" => "2020", "12", "30", "12", "34", "56", "789"
|
50
|
-
# ```
|
68
|
+
# Splits a string which represents a timestamp into components.
|
69
|
+
# Each component represents a part of constructs to instantiate
|
70
|
+
# a Time object.
|
51
71
|
#
|
72
|
+
# yyyymoddhhmiss sfx yyyy mo dd hh mi ss sfx
|
73
|
+
# "20201230123456" -> "2020", "12", "30", "12", "34", "56"
|
74
|
+
# "20201230123456_789" -> "2020", "12", "30", "12", "34", "56", "789"
|
75
|
+
|
52
76
|
def split_stamp(stamp_str)
|
53
77
|
# yyyy mo dd hh mi ss sfx
|
54
78
|
a = [0..3, 4..5, 6..7, 8..9, 10..11, 12..13, 15..17].map {|r| stamp_str[r]}
|
55
79
|
a[-1].nil? ? a[0..-2] : a
|
56
80
|
end
|
57
81
|
|
82
|
+
##
|
83
|
+
# Generate a Timestamp object from a string which represents a
|
84
|
+
# timestamp, such "20201028163400".
|
85
|
+
#
|
86
|
+
# :call-seq:
|
87
|
+
# parse_s("20201028163400") -> Timestamp
|
88
|
+
# parse_s("20201028163529_034") -> Timestamp
|
89
|
+
|
58
90
|
def parse_s(stamp_str)
|
59
91
|
year, mon, day, hour, min, sec , sfx = split_stamp(stamp_str).map(&:to_i)
|
60
92
|
Timestamp.new(Time.new(year, mon, day, hour, min, sec), sfx)
|
data/lib/textrepo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: textrepo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mnbi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|