mnbi / textrepo Goto Github PK
View Code? Open in Web Editor NEWA repository to store a note text with a timestamp
License: MIT License
A repository to store a note text with a timestamp
License: MIT License
Like FileTest.exist? in Ruby, the method returns true
when a note exists with the given timestamp in the repository. Otherwise, returns false
. If the argument is invalid as a timestamp string, it raises an error.
Is it annoying to change the timestamp with slight portion of change?
For example, just fix a typo.
So, Repository#update
needs an option to keep timestamp unchanged. When the option was specified, it would update only the content and it would not touch the timestamp.
The interface should be like:
Repository#update(timestamp, text, keep_stamp = false)
The third argument is optional, and it has a default value, false
. That is, this modification would not cause any inconsistency for existing client programs.
FileSystemRepository
has a private method, invoke_searcher_for_entries
. It accepts an Array object as one of its arguments, which holds timestamps of the target text. If the array is empty, the method must not do nothing. Then, it must return an empty output.
The current example in the examples
directory is too long to grab what textrepo
is.
Short usage will help people to visit this repository.
Could you write 3 lines usage to illustrate the characteristic of textrepo
?
Or 5 lines, 10 lines, ...
Repository#find
accepts on argument which specifies a timestamp pattern.
A timestamp pattern looks like, "20201016", "2020", "1016".
It returns an array of notes those timestamp match the pattern.
If no note match, an empty array will be returned.
How to construct a path from a Timestamp object is in the details of the implementation of the concrete repository class, that is FileSystemRepository. Timestamp class should not know the detail. It is against the low, "separation of concerns".
The word 'note' does not appear in any other place in this project except the example rbnotes
.
It should be some other name like entries
.
The repository name is written like this:
'mnbi/textrepo.git'
'.git' is needless in this form. It should be:
'mnbi/textrepo'
Typo in FileSystemRepository#invoke_searcher_for_entries
wrong: o.empty
-> correct: o.empty?
Add "2021" to the license text as the copyright year (update year).
When some md
file those have normal name such "hoge.md" exist in the repository directory, FileSystemRepository#entries
crashes.
FileSystemRepository#entries
returns an array. Currently, the array contains strings those are represents Timestamps. Should they be Timestamp objects?
The original concept of this method is intended to be written as:
repo = Textrepo.init(conf)
notes = repo.entries("20201027")
notes.each { |n|
repo.delete(n)
}
If entries
returns an array of string, user code must convert it to Timestamp object to use it with other Repository methods, since all other Repository methods accepts a Timestamp object instead of a string.
Version: 0.5.0
In the document of Repository#entries, a timestamp pattern "yyyymo" is in the acceptable patterns.
However, FileSystemRepository#entries
just ignores the pattern.
In the ri document of Repository#entries
, 4 digits pattern specifies year only or month and day.
However, in FileSystemRepository#entries
, 4 digits pattern such "1116" matches to not only "Nov. 16th" but "11:16" or "11 minute 16 second".
That is, FileSystemRepository#entries("1116")
might match the followings:
20201116131700
20200901111600
20201030121116
According to the spec (the ri doc), 1116
pattern must not match the 2nd and the 3rd ones.
At least, description of API for the following module/class is needed to use textrepo
.
All of BSD grep, GNU grep, and ripgrep have "-H" option. When use this option, filename will be shown as a prefix for each line of search result.
Using the option, the code of FileSystemRepository#invoke_searcher_for_entries
will be written more simple.
The description for v0.4.0 is missing.
No tag for v0.3.0.
It should be.
When nil
was passed to Timestamp#parse_s
, it generates such message:
invalid string as timestamp:
The error message has no information what is invalid.
It should be like:
invalid string as timestamp: (nil)
Enrich Timestamp class.
A Timestamp class object has two aspects. It could be handled as a Time object. In some case, it could be also handled as a String object. That is, some methods of Time class or String class are also useful to Timestamp class.
Currently, this repository does not work with Travis CI.
It must be enable it.
Following files has trailing spaces.
lib/textrepo/file_system_repository.rb
(65)lib/textrepo/timestmp.rb
(158)examples/rbnotes/lib/rbnotes/commands/list.rb
(39)test/fixtures/setup_test_repo.rb
(31)test/textrepo_timestamp_test.rb
(94)They should be removed.
Trailing spaces can be found using searcher like rg
. Here is an example to find:
> rg '[\s]+$'
Current implementation of FileSystemRepository#update always update the text in the repository even if the given content is identical to the text. Though the text is essentially unchanged, the timestamp is replaced with the new one. This behavior is weird.
It says:
search behavior equivalent to
grep
with "-inR". ...
However, in he below of the document, the description about the default value of the searcher options says:
"grep" => ["-i", "-n", "-R", "-E"]
It is an inconsistency. It seems that the former such "-inR" must be "-inRE".
Textrepo::Repository
APIs (such create
, read
, and update
) accept and return an array of text.
However, the definition is unclear.
In textrepo
and its client programs, "text" is defined as;
So, a newline code at the end of String object is needless.
This means that newlines must be removed from at the end of lines when they are read from the file.
However, the above definition is not documented. It must be.
To change Repository
class to Enumerable
,
Repository#each
Enumerable
This issue was originally opened against rbnotes
(mnbi/rbnotes#97).
Describe the symptom shortly again:
a. Timestamp.parse_s
raises InvalidTimestampStringError
when an invalid argument was passed such as "202012" (year and month), since some information is missing in the string. This behavior is correct. That is, it works as designed.
b. The same method causes a crash when a string was passed such as "20201211" (year and date). Though the string is also invalid as a timestamp, the crash is not correct behavior.
Update it.
The interface is to search full text in the repository. Currently, textrepo
assumes that all text is written in the UTF-8 encoding. So, the given search word must be in the UTF-8.
The API should be:
The only argument is a search keyword or a pattern (regular expression?).
Match information contains at lease a Timestamp object and line numbers contains the key word (or pattern).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.