class Textrepo::Repository
Attributes
Repository
name. The usage of the value of `name` depends on a concrete repository class. For example, `FileSystemRepository` uses it as a part of the repository path.
Repository
type. It specifies which concrete repository class will instantiated. For example, the type `:file_system` specifies `FileSystemRepository`.
Public Class Methods
Create a new repository. The argument must be an object which can be accessed like a Hash object.
# File lib/textrepo/repository.rb, line 24 def initialize(conf) @type = conf[:repository_type] @name = conf[:repository_name] end
Public Instance Methods
Stores text data into the repository with the specified timestamp. Returns the timestamp.
# File lib/textrepo/repository.rb, line 36 def create(timestamp, text); timestamp; end
Deletes the content in the repository, which is associated to the timestamp. Returns an array which contains the deleted text.
# File lib/textrepo/repository.rb, line 77 def delete(timestamp); []; end
Calls the given block once for each pair of timestamp and text in self, passing those pair as parameter. Returns the repository itself.
If no block is given, an Enumerator is returned.
# File lib/textrepo/repository.rb, line 137 def each(&block) if block.nil? entries.lazy.map { |timestamp| pair(timestamp) }.to_enum(:each) else entries.each { |timestamp| yield pair(timestamp) } self end end
Calls the given block once for each timestamp in self, passing the timestamp as a parameter. Returns the repository itself.
If no block is given, an Enumerator is returned.
# File lib/textrepo/repository.rb, line 154 def each_key(&block) if block.nil? entries.to_enum(:each) else entries.each(&block) end end
Calls the given block once for each timestamp in self, passing the text as a parameter. Returns the repository itself.
If no block is given, an Enumerator is returned.
# File lib/textrepo/repository.rb, line 170 def each_value(&block) if block.nil? entries.lazy.map { |timestamp| read(timestamp) }.to_enum(:each) else entries.each { |timestamp| yield read(timestamp) } end end
Finds all entries of text those have timestamps which mathes the specified pattern of timestamp. Returns an array which contains instances of Timestamp
. If none of text was found, an empty array would be returned.
A pattern must be one of the following: - yyyymoddhhmiss_lll : whole stamp - yyyymoddhhmiss : omit millisecond part - yyyymodd : date part only - yyyymo : month and year - yyyy : year only - modd : month and day
If `stamp_pattern` is omitted, the recent entries will be listed. Then, how many entries are listed depends on the implementaiton of the concrete repository class.
# File lib/textrepo/repository.rb, line 101 def entries(stamp_pattern = nil); []; end
Check the existence of text which is associated with the given timestamp.
# File lib/textrepo/repository.rb, line 110 def exist?(timestamp); false; end
Reads text data from the repository, which is associated to the timestamp. Returns an array which contains the text.
# File lib/textrepo/repository.rb, line 45 def read(timestamp); []; end
Searches a pattern (word or regular expression) in text those matches to a given timestamp pattern. Returns an Array of search results. If no match, returns an empty Array.
See the document for Repository#entries
about a timestamp pattern. When nil is passed as a timestamp pattern, searching applies to all text in the repository.
Each entry of the result Array is constructed from 3 items, (1) timestamp (Timestamp
), (2) line number (Integer), (3) matched line (String).
# File lib/textrepo/repository.rb, line 128 def search(pattern, stamp_pattern = nil); []; end
Updates the content with given text in the repository, which is associated to the given Timestamp
object. Returns the Timestamp
newly generated during the execution.
When true is passed as the third argument, keeps the Timestamp
unchanged, though updates the content. Then, returns the given Timestamp
object.
If the given Timestamp
object is not existed as a Timestamp
attached to text in the repository, raises MissingTimestampError
.
If the given text is empty, raises EmptyTextError
.
If the given text is identical to the text in the repository, does nothing. Returns the given timestamp itself.
# File lib/textrepo/repository.rb, line 68 def update(timestamp, text, keep_stamp = false); timestamp; end