From 2215da8651c525bcd29c91b6de8bed9ae295ede4 Mon Sep 17 00:00:00 2001 From: Nate Matykiewicz Date: Tue, 17 Sep 2024 15:07:00 -0500 Subject: [PATCH 1/6] Add RBI file --- Gemfile.lock | 4 +- bible_bot.gemspec | 2 +- lib/bible_bot.rb | 4 +- lib/bible_bot/verse.rb | 2 +- lib/bible_bot/version.rb | 2 +- rbi/bible_bot.rbi | 213 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 220 insertions(+), 7 deletions(-) create mode 100644 rbi/bible_bot.rbi diff --git a/Gemfile.lock b/Gemfile.lock index 2970d70..ebe1344 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - bible_bot (2.2.2) + bible_bot (2.2.3) i18n GEM @@ -29,7 +29,7 @@ GEM guard (~> 2.1) guard-compat (~> 1.1) rspec (>= 2.99.0, < 4.0) - i18n (1.14.5) + i18n (1.14.6) concurrent-ruby (~> 1.0) io-console (0.7.2) irb (1.11.1) diff --git a/bible_bot.gemspec b/bible_bot.gemspec index b0a019c..cff574f 100644 --- a/bible_bot.gemspec +++ b/bible_bot.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 3.1' - spec.files = Dir.glob('{lib}/**/*', File::FNM_DOTMATCH) + spec.files = Dir.glob('{lib,rbi}/**/*', File::FNM_DOTMATCH) spec.bindir = 'exe' spec.executables = [] spec.test_files = [] diff --git a/lib/bible_bot.rb b/lib/bible_bot.rb index 2214cc5..d2d4898 100644 --- a/lib/bible_bot.rb +++ b/lib/bible_bot.rb @@ -38,8 +38,8 @@ def self.include_apocryphal_content? !!self.options.include_apocryphal_content end - def self.include_apocryphal_content=(inc) - self.options.include_apocryphal_content = (inc == true) + def self.include_apocryphal_content=(include) + self.options.include_apocryphal_content = (include == true) # We need to reset the stored regexps because they take content into account. BibleBot::Bible.reset_regular_expressions diff --git a/lib/bible_bot/verse.rb b/lib/bible_bot/verse.rb index d7db523..a147c56 100644 --- a/lib/bible_bot/verse.rb +++ b/lib/bible_bot/verse.rb @@ -30,7 +30,7 @@ def self.from_id(id) # @param book_id [Integer] # @param chapter_number [Integer] # @param verse_number [Integer] - # @return [Array] + # @return [Integer] def self.integer_id(book_id:, chapter_number:, verse_number:) "#{book_id}#{chapter_number.to_s.rjust(3, '0')}#{verse_number.to_s.rjust(3, '0')}".to_i end diff --git a/lib/bible_bot/version.rb b/lib/bible_bot/version.rb index 050fe83..40141c7 100644 --- a/lib/bible_bot/version.rb +++ b/lib/bible_bot/version.rb @@ -1,3 +1,3 @@ module BibleBot - VERSION = "2.2.2" + VERSION = "2.2.3" end diff --git a/rbi/bible_bot.rbi b/rbi/bible_bot.rbi new file mode 100644 index 0000000..40d5ced --- /dev/null +++ b/rbi/bible_bot.rbi @@ -0,0 +1,213 @@ +# typed: strict + +module BibleBot + class << self + + sig { returns(include: T::Boolean) } + def include_apocryphal_content?; end + + sig { params(include: T::Boolean).void } + def include_apocryphal_content=(include); end + end +end + +class BibleBot::Bible + class << self + sig { returns(T::Array[BibleBot::Book]) } + def books; end + end +end + +class BibleBot::Book + class << self + sig { params(name: T.nilable(String)).returns(T.nilable(BibleBot::Book)) } + def find_by_name(name); end + + sig { params(code: T.nilable(String)).returns(T.nilable(BibleBot::Book)) } + def find_by_code(code); end + + sig { params(id: T.nilable(Integer)).returns(T.nilable(BibleBot::Book)) } + def find_by_id(id); end + end + + sig { returns(Integer) } + def id; end + + sig { returns(String) } + def name; end + + sig { returns(String) } + def abbreviation; end + + sig { returns(String) } + def dbl_code; end + + sig { returns(T::Array[Integer]) } + def chapters; end + + sig { returns(Symbol) } + def testament; end + + sig { returns(String) } + def testament_name; end + + sig { returns(T::Boolean) } + def apocryphal?; end + + sig { returns(String) } + def formatted_name; end + + sig { returns(String) } + def string_id; end + + sig { returns(BibleBot::Reference) } + def reference; end + + sig { returns(T::Array[String]) } + def chapter_string_ids; end + + sig { returns(T::Array[Integer]) } + def verse_ids; end + + sig { returns(BibleBot::Verse) } + def start_verse; end + + sig { returns(BibleBot::Verse) } + def end_verse; end + + sig { returns(T.nilable(BibleBot::Book)) } + def next_book; end +end + +class BibleBot::Verse + include Comparable + + class << self + sig { params(id: T.nilable(Integer)).returns(T.nilable(BibleBot::Verse)) } + def from_id(id); end + + sig { params(book_id: Integer, chapter_number: Integer, verse_number: Integer).returns(Integer) } + def integer_id(book_id:, chapter_number:, verse_number:); end + end + + sig { returns(BibleBot::Book) } + def book; end + + sig { returns(Integer) } + def chapter_number; end + + sig { returns(Integer) } + def verse_number; end + + sig { returns(Integer) } + def id; end + + sig { returns(String) } + def string_id; end + + sig { params(other: BibleBot::Verse).returns(Integer) } + def <=>(other); end + + sig { params(include_book: T::Boolean, include_chapter: T::Boolean, include_verse: T::Boolean).returns(String) } + def formatted(include_book: true, include_chapter: true, include_verse: true); end + + sig { returns(T.nilable(BibleBot::Verse)) } + def next_verse; end + + sig { returns(T::Boolean) } + def last_verse_in_chapter?; end + + sig { returns(T::Boolean) } + def last_verse_in_book?; end + + sig { returns(T::Boolean) } + def valid?; end + + sig { void } + def validate!; end +end + +class BibleBot::Reference + class << self + sig { params(start_verse_id: Integer, end_verse_id: T.nilable(Integer)).returns(BibleBot::Reference) } + def from_verse_ids(start_verse_id, end_verse_id = nil); end + + sig { params(text: String, validate: T::Boolean).returns(BibleBot::References) } + def parse(text, validate: false); end + + sig { params(text: String).returns(String) } + def normalize(text); end + + sig { params(text: String).returns(T::Array[String]) } + def normalize_by_chapter(text); end + end + + sig { returns(T::Verse) } + def start_verse; end + + sig { returns(T::Verse) } + def end_verse; end + + sig { returns(T::Boolean) } + def contains_apocrypha?; end + + sig { returns(String) } + def formatted; end + + sig { returns(T::Boolean) } + def same_start_and_end_book?; end + + sig { returns(T::Boolean) } + def same_start_and_end_chapter?; end + + sig { returns(T::Boolean) } + def full_chapters?; end + + sig { params(verse: BibleBot::Verse).returns(T::Boolean) } + def includes_verse?(verse); end + + sig { params(other: BibleBot::Reference).returns(T::Boolean) } + def intersects_reference?(other); end + + sig { returns(T::Array[BibleBot::Verse]) } + def verses; end + + sig { returns(T::Boolean) } + def valid?; end + + sig { void } + def validate!; end +end + +class BibleBot::References + include Enumerable + extend T::Generic + Elem = type_member(:out) { { fixed: BibleBot::Reference } } + + sig { returns(T::Array[Integer]) } + def ids; end + + sig { returns(T.nilable(String)) } + def formatted; end + + sig { returns(T::Boolean) } + def contains_apocrypha?; end + + sig { returns(BibleBot::References) } + def chapters; end + + sig { returns(T::Array[String]) } + def string_ids; end + + sig { returns(T::Boolean) } + def single_full_chapter?; end + + sig { returns(T::Boolean) } + def single_chapter?; end + + sig { returns(T::Boolean) } + def single_booko?; end + + sig { returns(T::Array[String]) } + def chapter_string_ids; end +end From 09d03c719d528077bdac5d248e3ac1ad7e0ac50a Mon Sep 17 00:00:00 2001 From: Nate Matykiewicz Date: Tue, 17 Sep 2024 15:24:50 -0500 Subject: [PATCH 2/6] This method also accepts a String --- lib/bible_bot/verse.rb | 2 +- rbi/bible_bot.rbi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bible_bot/verse.rb b/lib/bible_bot/verse.rb index a147c56..1646cea 100644 --- a/lib/bible_bot/verse.rb +++ b/lib/bible_bot/verse.rb @@ -10,7 +10,7 @@ class Verse # Turns an Integer into a Verse # For more details, see note above the `id` method. # - # @param id [Integer] + # @param id [Integer, String] # @return [Verse] # @example # Verse.from_id(19_105_001) #=> diff --git a/rbi/bible_bot.rbi b/rbi/bible_bot.rbi index 40d5ced..2e54b81 100644 --- a/rbi/bible_bot.rbi +++ b/rbi/bible_bot.rbi @@ -83,7 +83,7 @@ class BibleBot::Verse include Comparable class << self - sig { params(id: T.nilable(Integer)).returns(T.nilable(BibleBot::Verse)) } + sig { params(id: T.nilable(T.any(Integer, String)).returns(T.nilable(BibleBot::Verse)) } def from_id(id); end sig { params(book_id: Integer, chapter_number: Integer, verse_number: Integer).returns(Integer) } From a0c525e1c48acb6760e7e5e2809fa72ac5f1d007 Mon Sep 17 00:00:00 2001 From: Nate Matykiewicz Date: Tue, 17 Sep 2024 15:26:50 -0500 Subject: [PATCH 3/6] Oops --- rbi/bible_bot.rbi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rbi/bible_bot.rbi b/rbi/bible_bot.rbi index 2e54b81..25833b4 100644 --- a/rbi/bible_bot.rbi +++ b/rbi/bible_bot.rbi @@ -118,7 +118,7 @@ class BibleBot::Verse def last_verse_in_chapter?; end sig { returns(T::Boolean) } - def last_verse_in_book?; end + def last_chapter_in_book?; end sig { returns(T::Boolean) } def valid?; end From 54c0f3438b9762afcd98fcc1a9c02e049e30ec33 Mon Sep 17 00:00:00 2001 From: Nate Matykiewicz Date: Tue, 17 Sep 2024 15:31:22 -0500 Subject: [PATCH 4/6] These methods handle nils gracefully --- rbi/bible_bot.rbi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rbi/bible_bot.rbi b/rbi/bible_bot.rbi index 25833b4..c99d6a5 100644 --- a/rbi/bible_bot.rbi +++ b/rbi/bible_bot.rbi @@ -132,13 +132,13 @@ class BibleBot::Reference sig { params(start_verse_id: Integer, end_verse_id: T.nilable(Integer)).returns(BibleBot::Reference) } def from_verse_ids(start_verse_id, end_verse_id = nil); end - sig { params(text: String, validate: T::Boolean).returns(BibleBot::References) } + sig { params(text: T.nilable(String), validate: T::Boolean).returns(BibleBot::References) } def parse(text, validate: false); end - sig { params(text: String).returns(String) } + sig { params(text: T.nilable(String)).returns(String) } def normalize(text); end - sig { params(text: String).returns(T::Array[String]) } + sig { params(text: T.nilable(String)).returns(T::Array[String]) } def normalize_by_chapter(text); end end From 7bc593d5de1cdd7ddcd619b0e5c666a8ea1d3aeb Mon Sep 17 00:00:00 2001 From: Nate Matykiewicz Date: Tue, 17 Sep 2024 15:33:55 -0500 Subject: [PATCH 5/6] This is nilable --- rbi/bible_bot.rbi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rbi/bible_bot.rbi b/rbi/bible_bot.rbi index c99d6a5..2ee27fc 100644 --- a/rbi/bible_bot.rbi +++ b/rbi/bible_bot.rbi @@ -135,7 +135,7 @@ class BibleBot::Reference sig { params(text: T.nilable(String), validate: T::Boolean).returns(BibleBot::References) } def parse(text, validate: false); end - sig { params(text: T.nilable(String)).returns(String) } + sig { params(text: T.nilable(String)).returns(T.nilable(String)) } def normalize(text); end sig { params(text: T.nilable(String)).returns(T::Array[String]) } From df3306c712e2f40400efc1bd9f415df2e1969995 Mon Sep 17 00:00:00 2001 From: Nate Matykiewicz Date: Tue, 17 Sep 2024 15:34:39 -0500 Subject: [PATCH 6/6] Typo --- rbi/bible_bot.rbi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rbi/bible_bot.rbi b/rbi/bible_bot.rbi index 2ee27fc..ef4fdac 100644 --- a/rbi/bible_bot.rbi +++ b/rbi/bible_bot.rbi @@ -206,7 +206,7 @@ class BibleBot::References def single_chapter?; end sig { returns(T::Boolean) } - def single_booko?; end + def single_book?; end sig { returns(T::Array[String]) } def chapter_string_ids; end