diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 2a0d4b4..c3d88f1 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -23,6 +23,8 @@ jobs: bundler-cache: true - name: Run rubocop run: bundle exec rubocop + - name: Run rbs + steep + run: bundle exec steep check spec: runs-on: ubuntu-latest strategy: diff --git a/.rubocop.yml b/.rubocop.yml index a9c7643..0fb4c43 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1327,6 +1327,8 @@ Metrics/AbcSize: # The ABC size is a calculated magnitude, so this number can be an Integer or # a Float. Max: 20 + AllowedMethods: + - 'closest_node' Exclude: - 'tasks/*.rb' @@ -1353,6 +1355,9 @@ Metrics/ClassLength: # Avoid complex methods. Metrics/CyclomaticComplexity: Max: 6 + AllowedMethods: + - 'children_match_prefix' + - 'closest_node' Metrics/MethodLength: CountComments: false # count full line comments? diff --git a/Gemfile b/Gemfile index a915cc3..e3648cc 100644 --- a/Gemfile +++ b/Gemfile @@ -12,9 +12,11 @@ group :development do gem 'memory_profiler' gem 'pry' gem 'rake' + gem 'rbs' gem 'rspec' gem 'ruby-prof' gem 'stackprof' + gem 'steep' gem 'yard' end diff --git a/Steepfile b/Steepfile new file mode 100644 index 0000000..ca0e966 --- /dev/null +++ b/Steepfile @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +# D = Steep::Diagnostic +# +target :lib do + signature 'sig' + + check 'lib' + # check 'tasks' + + # check 'Gemfile' + # check 'Guardfile' + # check 'Rakefile' + # check 'Steepfile' + + # library 'rubyzip' + library 'yaml' + library 'securerandom' + + # configure_code_diagnostics(D::Ruby.default) # `default` diagnostics setting (applies by default) + # configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting + # configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting + # configure_code_diagnostics(D::Ruby.silent) # `silent` diagnostics setting + # configure_code_diagnostics do |hash| # You can setup everything yourself + # hash[D::Ruby::NoMethod] = :information + # end +end + +# target :test do +# signature 'sig', 'sig-private' +# +# check 'test' +# +# # library 'pathname' # Standard libraries +# end diff --git a/lib/rambling/trie.rb b/lib/rambling/trie.rb index 04c8fe2..e3b84a0 100644 --- a/lib/rambling/trie.rb +++ b/lib/rambling/trie.rb @@ -26,7 +26,7 @@ def create filepath = nil, reader = nil if filepath reader ||= readers.resolve filepath # noinspection RubyMismatchedArgumentType,RubyNilAnalysis - reader.each_word filepath do |word| + (reader || raise).each_word filepath do |word| container << word end end @@ -48,7 +48,7 @@ def create filepath = nil, reader = nil # discouraged. Only use the +.marshal+ format with trusted input. def load filepath, serializer = nil serializer ||= serializers.resolve filepath - root = serializer.load filepath + root = (serializer || raise).load filepath Rambling::Trie::Container.new root, compressor do |container| yield container if block_given? end @@ -66,7 +66,7 @@ def load filepath, serializer = nil def dump trie, filepath, serializer = nil serializer ||= serializers.resolve filepath # noinspection RubyNilAnalysis - serializer.dump trie.root, filepath + (serializer || raise).dump trie.root, filepath end # Provides configuration properties for the +Rambling::Trie+ gem. diff --git a/lib/rambling/trie/compressor.rb b/lib/rambling/trie/compressor.rb index 1314f92..c76e7b4 100644 --- a/lib/rambling/trie/compressor.rb +++ b/lib/rambling/trie/compressor.rb @@ -5,9 +5,11 @@ module Trie # Responsible for the compression process of a trie data structure. class Compressor # Compresses a {Nodes::Node Node} from a trie data structure. - # @param [Nodes::Raw] node the node to compress. + # @param [Nodes::Node] node the node to compress. # @return [Nodes::Compressed] node the compressed version of the node. def compress node + return if node.nil? + if node.compressible? compress_child_and_merge node else diff --git a/lib/rambling/trie/configuration/provider_collection.rb b/lib/rambling/trie/configuration/provider_collection.rb index 7e82743..df270df 100644 --- a/lib/rambling/trie/configuration/provider_collection.rb +++ b/lib/rambling/trie/configuration/provider_collection.rb @@ -104,7 +104,10 @@ def file_format filepath end def contains? provider - provider.nil? || (providers.any? && provider_instances.include?(provider)) + return true if provider.nil? + + p = (provider || raise) + providers.any? && provider_instances.include?(p) end alias_method :provider_instances, :values diff --git a/lib/rambling/trie/container.rb b/lib/rambling/trie/container.rb index b56edf4..b1dda0c 100644 --- a/lib/rambling/trie/container.rb +++ b/lib/rambling/trie/container.rb @@ -98,7 +98,7 @@ def scan word = '' # Returns all words within a string that match a word contained in the trie. # @param [String] phrase the string to look for matching words in. - # @return [Enumerator] all the words in the given string that match a word in the trie. + # @return [Array] all the words in the given string that match a word in the trie. # @yield [String] each word found in phrase. def words_within phrase words_within_root(phrase).to_a @@ -201,16 +201,18 @@ def words_within_root phrase return enum_for :words_within_root, phrase unless block_given? chars = phrase.chars + # rubocop:disable Style/CommentedKeyword 0.upto(chars.length - 1).each do |starting_index| - new_phrase = chars.slice starting_index..(chars.length - 1) + new_phrase = chars.slice starting_index..(chars.length - 1) # : Array[String] root.match_prefix new_phrase do |word| yield word end - end + end # : Enumerator[String, void] + # rubocop:enable Style/CommentedKeyword end def compress_root - compressor.compress root + compressor.compress root # : Nodes::Compressed end def char_symbols word diff --git a/lib/rambling/trie/enumerable.rb b/lib/rambling/trie/enumerable.rb index b3ca64f..7ffaee1 100644 --- a/lib/rambling/trie/enumerable.rb +++ b/lib/rambling/trie/enumerable.rb @@ -6,6 +6,8 @@ module Trie module Enumerable include ::Enumerable + EMPTY_ENUMERATOR = [].to_enum :each + # Returns number of words contained in the trie # @see https://ruby-doc.org/core-2.7.0/Enumerable.html#method-i-count Enumerable#count alias_method :size, :count diff --git a/lib/rambling/trie/nodes/compressed.rb b/lib/rambling/trie/nodes/compressed.rb index 5c901c2..d9fcc8c 100644 --- a/lib/rambling/trie/nodes/compressed.rb +++ b/lib/rambling/trie/nodes/compressed.rb @@ -23,13 +23,13 @@ def compressed? private def partial_word_chars? chars - child = children_tree[chars.first.to_sym] + child = children_tree[(chars.first || raise).to_sym] return false unless child child_letter = child.letter.to_s if chars.size >= child_letter.size - letter = chars.slice!(0, child_letter.size).join + letter = (chars.slice!(0, child_letter.size) || raise).join return child.partial_word? chars if child_letter == letter end @@ -39,7 +39,7 @@ def partial_word_chars? chars end def word_chars? chars - letter = chars.slice! 0 + letter = chars.slice!(0) || raise letter_sym = letter.to_sym child = children_tree[letter_sym] @@ -50,7 +50,7 @@ def word_chars? chars break if chars.empty? - letter << chars.slice!(0) + letter << (chars.slice!(0) || raise) letter_sym = letter.to_sym end @@ -58,13 +58,13 @@ def word_chars? chars end def closest_node chars - child = children_tree[chars.first.to_sym] + child = children_tree[(chars.first || raise).to_sym] return missing unless child child_letter = child.letter.to_s if chars.size >= child_letter.size - letter = chars.slice!(0, child_letter.size).join + letter = (chars.slice!(0, child_letter.size) || raise).join return child.scan chars if child_letter == letter end @@ -77,15 +77,15 @@ def closest_node chars def children_match_prefix chars return enum_for :children_match_prefix, chars unless block_given? - return if chars.empty? + return EMPTY_ENUMERATOR if chars.empty? - child = children_tree[chars.first.to_sym] - return unless child + child = children_tree[(chars.first || raise).to_sym] + return EMPTY_ENUMERATOR unless child child_letter = child.letter.to_s - letter = chars.slice!(0, child_letter.size).join + letter = (chars.slice!(0, child_letter.size) || raise).join - return unless child_letter == letter + return EMPTY_ENUMERATOR unless child_letter == letter child.match_prefix chars do |word| yield word diff --git a/lib/rambling/trie/nodes/node.rb b/lib/rambling/trie/nodes/node.rb index 4163e9d..d0a495c 100644 --- a/lib/rambling/trie/nodes/node.rb +++ b/lib/rambling/trie/nodes/node.rb @@ -52,6 +52,8 @@ def first_child # rubocop:disable Lint/UnreachableLoop children_tree.each_value { |child| return child } # rubocop:enable Lint/UnreachableLoop + + nil end # Indicates if the current node is the root node. @@ -106,7 +108,7 @@ def scan chars end # Returns all words that match a prefix of any length within chars. - # @param [String] chars the chars to base the prefix on. + # @param [Array[String]] chars the chars to base the prefix on. # @return [Enumerator] all the words that match a prefix by chars. # @yield [String] each word found. def match_prefix chars @@ -147,7 +149,7 @@ def key? letter # Delete a given letter and its corresponding {Node Node} from # this {Node Node}'s children tree. # @param [Symbol] letter the letter to delete from the node's children tree. - # @return [Node] the node corresponding to the deleted letter. + # @return [Node, nil] the node corresponding to the deleted letter. # @see https://ruby-doc.org/core-2.7.0/Hash.html#method-i-delete Hash#delete def delete letter children_tree.delete letter diff --git a/lib/rambling/trie/nodes/raw.rb b/lib/rambling/trie/nodes/raw.rb index 1a225db..1c3558d 100644 --- a/lib/rambling/trie/nodes/raw.rb +++ b/lib/rambling/trie/nodes/raw.rb @@ -7,7 +7,7 @@ module Nodes class Raw < Rambling::Trie::Nodes::Node # Adds a word to the current raw (uncompressed) trie node. # @param [Array] chars the char array to add to the trie. - # @return [Raw] the added/modified node based on the word added. + # @return [Node] the added/modified node based on the word added. # @note This method clears the contents of the chars variable. def add chars if chars.empty? @@ -27,7 +27,7 @@ def compressed? private def add_to_children_tree chars - letter = chars.pop + letter = chars.pop || raise child = children_tree[letter] || new_node(letter) child.add chars child @@ -40,7 +40,7 @@ def new_node letter end def partial_word_chars? chars = [] - letter = chars.shift.to_sym + letter = (chars.shift || raise).to_sym child = children_tree[letter] return false unless child @@ -48,7 +48,7 @@ def partial_word_chars? chars = [] end def word_chars? chars = [] - letter = chars.shift.to_sym + letter = (chars.shift || raise).to_sym child = children_tree[letter] return false unless child @@ -56,7 +56,7 @@ def word_chars? chars = [] end def closest_node chars - letter = chars.shift.to_sym + letter = (chars.shift || raise).to_sym child = children_tree[letter] return missing unless child @@ -66,12 +66,12 @@ def closest_node chars def children_match_prefix chars return enum_for :children_match_prefix, chars unless block_given? - return if chars.empty? + return EMPTY_ENUMERATOR if chars.empty? - letter = chars.shift.to_sym + letter = (chars.shift || raise).to_sym child = children_tree[letter] - return unless child + return EMPTY_ENUMERATOR unless child child.match_prefix chars do |word| yield word diff --git a/lib/rambling/trie/serializers/zip.rb b/lib/rambling/trie/serializers/zip.rb index 809fbc9..b90ffb9 100644 --- a/lib/rambling/trie/serializers/zip.rb +++ b/lib/rambling/trie/serializers/zip.rb @@ -26,12 +26,14 @@ def load filepath ::Zip::File.open filepath do |zip| entry = zip.entries.first - return nil if entry.nil? + raise if entry.nil? entry_path = path entry.name entry.extract entry_path serializer = serializers.resolve entry.name + raise if serializer.nil? + serializer.load entry_path end end @@ -50,6 +52,9 @@ def dump contents, filepath entry_path = path filename serializer = serializers.resolve filename + + raise if serializer.nil? + serializer.dump contents, entry_path zip.add filename, entry_path diff --git a/sig/lib/rambling/trie.rbs b/sig/lib/rambling/trie.rbs new file mode 100644 index 0000000..9451f7b --- /dev/null +++ b/sig/lib/rambling/trie.rbs @@ -0,0 +1,27 @@ +module Rambling + module Trie + VERSION: String + + @properties: Configuration::Properties + + def self.create: (?String?, ?Readers::Reader?) ?{ (Container) -> void } -> Container + + def self.load: (String, ?Serializers::Serializer[Nodes::Node]?) ?{ (Container) -> void } -> Container + + def self.dump: (Container, String, ?Serializers::Serializer[Nodes::Node]?) -> void + + def self.config: ?{ (Configuration::Properties) -> void } -> Configuration::Properties + + private + + def self.properties: -> Configuration::Properties + + def self.readers: -> Configuration::ProviderCollection[Readers::Reader] + + def self.serializers: -> Configuration::ProviderCollection[Serializers::Serializer[Nodes::Node]] + + def self.compressor: -> Compressor + + def self.root_builder: -> ^() -> Nodes::Node + end +end diff --git a/sig/lib/rambling/trie/comparable.rbs b/sig/lib/rambling/trie/comparable.rbs new file mode 100644 index 0000000..7b2a6e6 --- /dev/null +++ b/sig/lib/rambling/trie/comparable.rbs @@ -0,0 +1,17 @@ +module Rambling + module Trie + module Comparable + def ==: (Nodes::Node) -> bool + + private + + # abstract methods + + def letter: -> Symbol + + def terminal?: -> bool + + def children_tree: -> Hash[Symbol, Nodes::Node] + end + end +end diff --git a/sig/lib/rambling/trie/compressible.rbs b/sig/lib/rambling/trie/compressible.rbs new file mode 100644 index 0000000..774335c --- /dev/null +++ b/sig/lib/rambling/trie/compressible.rbs @@ -0,0 +1,17 @@ +module Rambling + module Trie + module Compressible + def compressible?: -> bool + + private + + # abstract methods + + def root?: -> bool + + def terminal?: -> bool + + def children_tree: -> Hash[Symbol, Nodes::Node] + end + end +end diff --git a/sig/lib/rambling/trie/compressor.rbs b/sig/lib/rambling/trie/compressor.rbs new file mode 100644 index 0000000..96181b9 --- /dev/null +++ b/sig/lib/rambling/trie/compressor.rbs @@ -0,0 +1,19 @@ +module Rambling + module Trie + class Compressor + def compress: (Nodes::Node?) -> Nodes::Compressed? + + private + + def compress_child_and_merge: (Nodes::Node) -> Nodes::Compressed + + def merge: (Nodes::Node, Nodes::Node?) -> Nodes::Compressed + + def compress_children_and_copy: (Nodes::Node) -> Nodes::Compressed + + def compress_children: (Hash[Symbol, Nodes::Node]) -> Hash[Symbol, Nodes::Node] + + def new_compressed_node: (Symbol?, Nodes::Node?, Hash[Symbol, Nodes::Node], bool?) -> Nodes::Compressed + end + end +end diff --git a/sig/lib/rambling/trie/configuration/properties.rbs b/sig/lib/rambling/trie/configuration/properties.rbs new file mode 100644 index 0000000..29e0808 --- /dev/null +++ b/sig/lib/rambling/trie/configuration/properties.rbs @@ -0,0 +1,28 @@ +module Rambling + module Trie + module Configuration + class Properties + attr_reader readers: ProviderCollection[Readers::Reader] + attr_reader serializers: ProviderCollection[Serializers::Serializer[Nodes::Node]] + attr_accessor compressor: Compressor + attr_accessor root_builder: ^() -> Nodes::Node + attr_accessor tmp_path: String + + def initialize: -> void + + def reset: -> void + + private + + attr_writer readers: ProviderCollection[Readers::Reader] + attr_writer serializers: ProviderCollection[Serializers::Serializer[Nodes::Node]] + + def reset_readers: -> void + + def default_reader_providers: -> Hash[Symbol, Readers::Reader] + + def reset_serializers: -> void + end + end + end +end diff --git a/sig/lib/rambling/trie/configuration/provider_collection.rbs b/sig/lib/rambling/trie/configuration/provider_collection.rbs new file mode 100644 index 0000000..8d8b497 --- /dev/null +++ b/sig/lib/rambling/trie/configuration/provider_collection.rbs @@ -0,0 +1,47 @@ +module Rambling + module Trie + module Configuration + class ProviderCollection[TProvider < _Nilable] + interface _Nilable + def nil?: -> bool + end + + @providers: Hash[Symbol, TProvider] + + attr_reader name: Symbol + attr_reader default: TProvider? + + def initialize: (Symbol, Hash[Symbol, TProvider], ?TProvider?) -> void + + def []: (Symbol) -> TProvider + + def add: (Symbol, TProvider) -> TProvider + + def default=: (TProvider?) -> TProvider? + + def formats: -> Array[Symbol] + + def providers: -> Hash[Symbol, TProvider] + + def reset: -> void + + def resolve: (String) -> TProvider? + + private + + attr_reader configured_default: TProvider? + attr_reader configured_providers: Hash[Symbol, TProvider] + + def []=: (Symbol, TProvider) -> TProvider + + def values: -> Array[TProvider] + + def file_format: (String) -> Symbol + + def contains?: (TProvider?) -> bool + + alias provider_instances values + end + end + end +end diff --git a/sig/lib/rambling/trie/container.rbs b/sig/lib/rambling/trie/container.rbs new file mode 100644 index 0000000..f0627f9 --- /dev/null +++ b/sig/lib/rambling/trie/container.rbs @@ -0,0 +1,69 @@ +module Rambling + module Trie + class Container + include ::Enumerable[String] + + @compressor: Compressor + + attr_reader root: Nodes::Node + + def initialize: (Nodes::Node, Compressor) ?{ (Container) -> void } -> void + + def add: (String) -> Nodes::Node + + def concat: (Array[String]) -> Array[Nodes::Node] + + def compress!: -> Container + + def compress: -> Container + + def each: { (String) -> void } -> (Enumerator[String, void] | Enumerable) + + def partial_word?: (String) -> bool + + def push: (*String) -> Array[Nodes::Node] + + def word?: (String) -> bool + + def scan: (String) -> Array[String] + + def words_within: (String) -> Array[String] + + def words_within?: (String) -> bool + + def ==: (Container) -> bool + + def []: (Symbol) -> Nodes::Node + + def children: -> Array[Nodes::Node] + + def children_tree: -> Hash[Symbol, Nodes::Node] + + def compressed?: -> bool + + def to_a: -> Array[String] + + def key?: (Symbol) -> bool + + def size: -> Numeric + + alias include? word? + alias match? partial_word? + alias words? scan + alias << add + alias has_key? key? + alias has_letter? key? + + private + + attr_reader compressor: Compressor + attr_writer root: Nodes::Node + + def words_within_root: (String) ?{ (String) -> void } -> Enumerator[String, void] + + def compress_root: -> Nodes::Compressed + + def char_symbols: (String) -> Array[Symbol] + end + end +end diff --git a/sig/lib/rambling/trie/enumerable.rbs b/sig/lib/rambling/trie/enumerable.rbs new file mode 100644 index 0000000..efec895 --- /dev/null +++ b/sig/lib/rambling/trie/enumerable.rbs @@ -0,0 +1,23 @@ +module Rambling + module Trie + module Enumerable + include ::Enumerable[String] + + EMPTY_ENUMERATOR: Enumerator[String, void] + + alias size count + + def each: { (String) -> void } -> (Enumerator[String, void] | Enumerable) + + private + + # abstract methods + + def as_word: -> String + + def terminal?: -> bool + + def children_tree: -> Hash[Symbol, Nodes::Node] + end + end +end diff --git a/sig/lib/rambling/trie/inspectable.rbs b/sig/lib/rambling/trie/inspectable.rbs new file mode 100644 index 0000000..600e2a2 --- /dev/null +++ b/sig/lib/rambling/trie/inspectable.rbs @@ -0,0 +1,27 @@ +module Rambling + module Trie + module Inspectable + def inspect: -> String + + private + + def class_name: -> String? + + def attributes: -> String + + def letter_inspect: -> String + + def terminal_inspect: -> String + + def children_inspect: -> String + + # abstract methods + + def letter: -> Symbol + + def terminal: -> bool? + + def children_tree: -> Hash[Symbol, Nodes::Node] + end + end +end diff --git a/sig/lib/rambling/trie/invalid_operation.rbs b/sig/lib/rambling/trie/invalid_operation.rbs new file mode 100644 index 0000000..f35485b --- /dev/null +++ b/sig/lib/rambling/trie/invalid_operation.rbs @@ -0,0 +1,7 @@ +module Rambling + module Trie + class InvalidOperation < RuntimeError + def initialize: (String? message) -> void + end + end +end diff --git a/sig/lib/rambling/trie/nodes/compressed.rbs b/sig/lib/rambling/trie/nodes/compressed.rbs new file mode 100644 index 0000000..ef76a63 --- /dev/null +++ b/sig/lib/rambling/trie/nodes/compressed.rbs @@ -0,0 +1,21 @@ +module Rambling + module Trie + module Nodes + class Compressed < Node + def add: (Array[Symbol]) -> Node + + def compressed?: -> bool + + private + + def partial_word_chars?: (Array[String]) -> bool + + def word_chars?: (Array[String]) -> bool + + def closest_node: (Array[String]) -> Node + + def children_match_prefix: (Array[String]) { (String) -> void } -> Enumerator[String, void] + end + end + end +end diff --git a/sig/lib/rambling/trie/nodes/missing.rbs b/sig/lib/rambling/trie/nodes/missing.rbs new file mode 100644 index 0000000..f84d9c4 --- /dev/null +++ b/sig/lib/rambling/trie/nodes/missing.rbs @@ -0,0 +1,9 @@ +module Rambling + module Trie + module Nodes + class Missing < Node + def initialize: -> void + end + end + end +end \ No newline at end of file diff --git a/sig/lib/rambling/trie/nodes/node.rbs b/sig/lib/rambling/trie/nodes/node.rbs new file mode 100644 index 0000000..cab7efa --- /dev/null +++ b/sig/lib/rambling/trie/nodes/node.rbs @@ -0,0 +1,69 @@ +module Rambling + module Trie + module Nodes + class Node + include Compressible + include Enumerable + include Comparable + include Stringifyable + include Inspectable + + attr_reader letter: Symbol? + attr_accessor children_tree: Hash[Symbol, Node] + attr_accessor parent: Node? + + def initialize: (?Symbol?, ?Node?, ?Hash[Symbol, Node]) -> void + + def add: (Array[Symbol]) -> Node + + def children: -> Array[Node] + + def first_child: -> Node? + + def match_prefix: (Array[String]) { (String) -> void } -> Enumerator[String, void] + + def root?: -> bool + + def scan: (Array[String]) -> Node + + def terminal?: -> bool + + def terminal!: -> Node + + def letter=: (String | Symbol?) -> Symbol? + + def compressed?: -> bool + + def partial_word?: (Array[String]) -> bool + + def word?: (Array[String]) -> bool + + def []: (Symbol) -> Node + + def []=: (Symbol, Node) -> Node + + def key?: (Symbol) -> bool + + def delete: (Symbol) -> Node? + + alias has_key? key? + + private + + def missing: -> Node + + attr_accessor terminal: bool? + + # abstract methods + + def partial_word_chars?: (Array[String]) -> bool + + def word_chars?: (Array[String]) -> bool + + def closest_node: (Array[String]) -> Node + + def children_match_prefix: (Array[String]) { (String) -> void } -> Enumerator[String, void] + end + end + end +end diff --git a/sig/lib/rambling/trie/nodes/raw.rbs b/sig/lib/rambling/trie/nodes/raw.rbs new file mode 100644 index 0000000..a7440f4 --- /dev/null +++ b/sig/lib/rambling/trie/nodes/raw.rbs @@ -0,0 +1,25 @@ +module Rambling + module Trie + module Nodes + class Raw < Node + def add: (Array[Symbol]) -> Node + + def compressed?: -> bool + + private + + def add_to_children_tree: (Array[Symbol]) -> Node + + def new_node: (Symbol) -> Node + + def partial_word_chars?: (Array[String]) -> bool + + def word_chars?: (Array[String]) -> bool + + def closest_node: (Array[String]) -> Node + + def children_match_prefix: (Array[String]) { (String) -> void } -> Enumerator[String, void] + end + end + end +end diff --git a/sig/lib/rambling/trie/readers/plain_text.rbs b/sig/lib/rambling/trie/readers/plain_text.rbs new file mode 100644 index 0000000..4653dcc --- /dev/null +++ b/sig/lib/rambling/trie/readers/plain_text.rbs @@ -0,0 +1,9 @@ +module Rambling + module Trie + module Readers + class PlainText < Reader + def each_word: (String) { (String?) -> void } -> (Enumerator[String?, void] | PlainText) + end + end + end +end \ No newline at end of file diff --git a/sig/lib/rambling/trie/readers/reader.rbs b/sig/lib/rambling/trie/readers/reader.rbs new file mode 100644 index 0000000..6e0e791 --- /dev/null +++ b/sig/lib/rambling/trie/readers/reader.rbs @@ -0,0 +1,9 @@ +module Rambling + module Trie + module Readers + class Reader + def each_word: (String) { (String) -> void } -> (Enumerator[String, void] | Reader) + end + end + end +end diff --git a/sig/lib/rambling/trie/serializers/file.rbs b/sig/lib/rambling/trie/serializers/file.rbs new file mode 100644 index 0000000..04a2caf --- /dev/null +++ b/sig/lib/rambling/trie/serializers/file.rbs @@ -0,0 +1,8 @@ +module Rambling + module Trie + module Serializers + class File < Serializer[String] + end + end + end +end diff --git a/sig/lib/rambling/trie/serializers/marshal.rbs b/sig/lib/rambling/trie/serializers/marshal.rbs new file mode 100644 index 0000000..6f9e5b3 --- /dev/null +++ b/sig/lib/rambling/trie/serializers/marshal.rbs @@ -0,0 +1,13 @@ +module Rambling + module Trie + module Serializers + class Marshal < Serializer[Nodes::Node] + @serializer: Serializer[String] + + private + + attr_reader serializer: Serializer[String] + end + end + end +end diff --git a/sig/lib/rambling/trie/serializers/serializer.rbs b/sig/lib/rambling/trie/serializers/serializer.rbs new file mode 100644 index 0000000..f05100b --- /dev/null +++ b/sig/lib/rambling/trie/serializers/serializer.rbs @@ -0,0 +1,10 @@ +module Rambling + module Trie + module Serializers + class Serializer[TContents] + def load: (String) -> TContents + def dump: (TContents, String) -> Numeric + end + end + end +end diff --git a/sig/lib/rambling/trie/serializers/yaml.rbs b/sig/lib/rambling/trie/serializers/yaml.rbs new file mode 100644 index 0000000..a647977 --- /dev/null +++ b/sig/lib/rambling/trie/serializers/yaml.rbs @@ -0,0 +1,13 @@ +module Rambling + module Trie + module Serializers + class Yaml < Serializer[Nodes::Node] + @serializer: Serializer[String] + + private + + attr_reader serializer: Serializer[String] + end + end + end +end diff --git a/sig/lib/rambling/trie/serializers/zip.rbs b/sig/lib/rambling/trie/serializers/zip.rbs new file mode 100644 index 0000000..083d0da --- /dev/null +++ b/sig/lib/rambling/trie/serializers/zip.rbs @@ -0,0 +1,21 @@ +module Rambling + module Trie + module Serializers + class Zip < Serializer[Nodes::Node] + @properties: Configuration::Properties + + def initialize: (Configuration::Properties) -> void + + private + + attr_reader properties: Configuration::Properties + + def serializers: -> Configuration::ProviderCollection[Serializer[Nodes::Node]] + + def tmp_path: -> String + + def path: (String) -> String + end + end + end +end diff --git a/sig/lib/rambling/trie/stringifyable.rbs b/sig/lib/rambling/trie/stringifyable.rbs new file mode 100644 index 0000000..e012c9a --- /dev/null +++ b/sig/lib/rambling/trie/stringifyable.rbs @@ -0,0 +1,21 @@ +module Rambling + module Trie + module Stringifyable + def as_word: -> String + + def to_s: -> String + + private + + # abstract methods + + def letter: -> Symbol + + def terminal?: -> bool + + def parent: -> Nodes::Node? + + def children_tree: -> Hash[Symbol, Nodes::Node] + end + end +end diff --git a/sig/lib/zip/entry.rbs b/sig/lib/zip/entry.rbs new file mode 100644 index 0000000..21f798c --- /dev/null +++ b/sig/lib/zip/entry.rbs @@ -0,0 +1,11 @@ +module Zip + class Entry + include Enumerable[Entry] + + def name: -> String + + def extract: (String) -> void + + def each: ?{ (Entry) -> void } -> (Enumerator[Entry, void]) + end +end \ No newline at end of file diff --git a/sig/lib/zip/file.rbs b/sig/lib/zip/file.rbs new file mode 100644 index 0000000..bd38cfa --- /dev/null +++ b/sig/lib/zip/file.rbs @@ -0,0 +1,11 @@ +module Zip + class File + CREATE: bool + + def self.open: [TContent] (String, ?bool?) { (File) -> TContent } -> TContent + + def entries: -> Array[Entry] + + def add: (String, String) -> void + end +end \ No newline at end of file