textrepo 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7415dcbc8ec9483a33c0027432a60473fd0b77ad67369b25b88fb0f399edd788
4
- data.tar.gz: 9467336f5d93ec578d5693005a4737f4eef55aeb11e4c0a4ec12f197e81de240
3
+ metadata.gz: 24594803cdcc722b7a9ca01648a9d8955cb9637669ab1c459e653c2eb2d2c199
4
+ data.tar.gz: bc5802a9a1df190d2278163b25d5ff1d2d107223acec17a3e713d1daf30a2218
5
5
  SHA512:
6
- metadata.gz: f989032a0f1db66aeb1392cf9b05fd89306152d1b76907953c90ec14839d7a34465a017a2be8017536270b9a071cd3027497305978fdf59681d3547c8a68a5e5
7
- data.tar.gz: cfb126c03ce9720dd2f2e90453a5d2baf33160c7786a8a1d9b5ef02b2c4a4e2531de5744d255efd7979a39e87c9e93287de3397533404143b51be1eb8bb23a58
6
+ metadata.gz: 21ef95e13e30d816b671be203b7beffa1ab022aec94bfc9540a7712f548cbf5749a8f5dc8f13e1f22067f53f52ac63dd2ac75ffa32719d72deb49b6b410c05a3
7
+ data.tar.gz: bef5bcfbef5a5557f80c44035dd42a9c8474cb04836e3328a6b0a7f0c065d5b601ff92bfcd4dee4a7a7c3273ac9e0648ae7a1e3bb52acdd95627de9266a04767
@@ -1,12 +1,36 @@
1
1
  module Textrepo
2
+
3
+ ##
4
+ # Following errors might occur in repository operations:
5
+ # +--------------------------+---------------------+
6
+ # | operation (args) | error type |
7
+ # +--------------------------+---------------------+
8
+ # | create (timestamp, text) | Duplicate timestamp |
9
+ # | | Empty text |
10
+ # +--------------------------+---------------------+
11
+ # | read (timestamp) | Missing timestamp |
12
+ # +--------------------------+---------------------+
13
+ # | update (timestamp, text) | Mssing timestamp |
14
+ # | | Empty text |
15
+ # +--------------------------+---------------------+
16
+ # | delete (timestamp) | Missing timestamp |
17
+ # +--------------------------+---------------------+
18
+
2
19
  class Error < StandardError; end
3
20
 
21
+ # :stopdoc:
4
22
  module ErrMsg
5
23
  UNKNOWN_REPO_TYPE = 'unknown type for repository: %s'
6
24
  DUPLICATE_TIMESTAMP = 'duplicate timestamp: %s'
7
25
  EMPTY_TEXT = 'empty text'
8
26
  MISSING_TIMESTAMP = 'missing timestamp: %s'
27
+ INVALID_TIMESTAMP_STRING = "invalid string as timestamp: %s"
9
28
  end
29
+ # :startdoc:
30
+
31
+ ##
32
+ # An error raised if unknown type was specified as the repository
33
+ # type.
10
34
 
11
35
  class UnknownRepoTypeError < Error
12
36
  def initialize(type)
@@ -14,20 +38,9 @@ module Textrepo
14
38
  end
15
39
  end
16
40
 
17
- # Following errors might occur in repository operations:
18
- # +--------------------------+---------------------+
19
- # | operation (args) | error type |
20
- # +--------------------------+---------------------+
21
- # | create (timestamp, text) | Duplicate timestamp |
22
- # | | Empty text |
23
- # +--------------------------+---------------------+
24
- # | read (timestamp) | Missing timestamp |
25
- # +--------------------------+---------------------+
26
- # | update (timestamp, text) | Mssing timestamp |
27
- # | | Empty text |
28
- # +--------------------------+---------------------+
29
- # | delete (timestamp) | Missing timestamp |
30
- # +--------------------------+---------------------+
41
+ ##
42
+ # An error raised if the specified timestamp has already exist in
43
+ # the repository.
31
44
 
32
45
  class DuplicateTimestampError < Error
33
46
  def initialize(timestamp)
@@ -35,16 +48,33 @@ module Textrepo
35
48
  end
36
49
  end
37
50
 
51
+ ##
52
+ # An error raised if the given text is empty.
53
+
38
54
  class EmptyTextError < Error
39
55
  def initialize
40
56
  super(ErrMsg::EMPTY_TEXT)
41
57
  end
42
58
  end
43
59
 
60
+ ##
61
+ # An error raised if the given timestamp has not exist in the
62
+ # repository.
63
+
44
64
  class MissingTimestampError < Error
45
65
  def initialize(timestamp)
46
66
  super(ErrMsg::MISSING_TIMESTAMP % timestamp)
47
67
  end
48
68
  end
49
69
 
70
+ ##
71
+ # An error raised if an argument is invalid to convert a
72
+ # Textrepo::Timestamp object.
73
+
74
+ class InvalidTimestampStringError < Error
75
+ def initialize(str)
76
+ super(ErrMsg::INVALID_TIMESTAMP_STRING % str)
77
+ end
78
+ end
79
+
50
80
  end
@@ -208,9 +208,18 @@ module Textrepo
208
208
 
209
209
  def find_entries(stamp_pattern)
210
210
  Dir.glob("#{@path}/**/#{stamp_pattern}*.#{@extname}").map { |e|
211
- Timestamp.parse_s(timestamp_str(e))
212
- }
211
+ begin
212
+ Timestamp.parse_s(timestamp_str(e))
213
+ rescue InvalidTimestampStringError => _
214
+ # Just ignore the erroneous entry, since it is not a text in
215
+ # the repository. It may be a garbage, or some kind of
216
+ # hidden stuff of the repository, ... etc.
217
+ nil
218
+ end
219
+ }.compact
213
220
  end
214
221
 
222
+ # :startdoc:
223
+
215
224
  end
216
225
  end
@@ -72,8 +72,11 @@ module Textrepo
72
72
  # yyyymoddhhmiss sfx yyyy mo dd hh mi ss sfx
73
73
  # "20201230123456" -> "2020", "12", "30", "12", "34", "56"
74
74
  # "20201230123456_789" -> "2020", "12", "30", "12", "34", "56", "789"
75
+ #
76
+ # Raises InvalidTimestampStringError if nil was passed as an arguemnt.
75
77
 
76
78
  def split_stamp(stamp_str)
79
+ raise InvalidTimestampStringError, stamp_str if stamp_str.nil?
77
80
  # yyyy mo dd hh mi ss sfx
78
81
  a = [0..3, 4..5, 6..7, 8..9, 10..11, 12..13, 15..17].map {|r| stamp_str[r]}
79
82
  a[-1].nil? ? a[0..-2] : a
@@ -83,13 +86,20 @@ module Textrepo
83
86
  # Generate a Timestamp object from a string which represents a
84
87
  # timestamp, such "20201028163400".
85
88
  #
89
+ # Raises InvalidTimestampStringError if cannot convert the
90
+ # argument into a Timestamp object.
91
+ #
86
92
  # :call-seq:
87
93
  # parse_s("20201028163400") -> Timestamp
88
94
  # parse_s("20201028163529_034") -> Timestamp
89
95
 
90
96
  def parse_s(stamp_str)
91
- year, mon, day, hour, min, sec , sfx = split_stamp(stamp_str).map(&:to_i)
92
- Timestamp.new(Time.new(year, mon, day, hour, min, sec), sfx)
97
+ begin
98
+ ye, mo, da, ho, mi, se, sfx = split_stamp(stamp_str).map(&:to_i)
99
+ Timestamp.new(Time.new(ye, mo, da, ho, mi, se), sfx)
100
+ rescue InvalidTimestampStringError, ArgumentError => _
101
+ raise InvalidTimestampStringError, stamp_str
102
+ end
93
103
  end
94
104
 
95
105
  end
@@ -1,3 +1,3 @@
1
1
  module Textrepo
2
- VERSION = '0.4.4'
2
+ VERSION = '0.4.5'
3
3
  end
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
4
+ version: 0.4.5
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-28 00:00:00.000000000 Z
11
+ date: 2020-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler