Thor CLI KJV Bible Search Engine – part 2

In part 1 I showed how I created a simple CLI (command line interface) Bible Search Engine. The problem is that one must always reference the path to the Bible text files. So I will create a Thor task which will eliminate this dependence on the user giving a path (or having to change to the text file directory). First, I create a directory called bbl (which means Bible) inside my _thor directory (which is just a collection of task directories) and then copy the source files there. I’ll create a bbl.rb file which holds my Ruby code creating a Thor task.
[code]
_thor/bbl$ ls
bbl.rb books

_thor/bbl$ more bbl.rb
class Bbl < Thor

def self.source_root
# the permanent location of the text files on my system
‘~/projects/_thor/bbl/books’
end

end
Now we can install the Thor task so the system always knows about it:
[code]
_thor/bbl$ thor install bbl.rb
Please specify a name for bbl.rb in the system repository [bbl.rb]: bbl
Storing thor file in your system repository
[/code]

[code]
_thor/bbl$ thor installed
Modules Namespaces
——- ———-
bbl bbl

bbl

thor bbl:find [PHRASE] # find a phase given as list of words on param line
[/code]

Now we can search through the Bible from anywhere on the system. Here is an example from the home directory:
[code]
author@his-laptop:~$ cd ~
author@his-laptop:~$ thor bbl:find "thou art a priest"
psalms 110:004 The LORD hath sworn, and will not repent, Thou art a priest for ever after the order of Melchizedek.
hebrews 005:006 As he saith also in another place, Thou art a priest for ever after the order of Melchisedec.
hebrews 007:017 For he testifieth, Thou art a priest for ever after the order of Melchisedec.
hebrews 007:021 (For those priests were made without an oath; but this with an oath by him that said unto him, The Lord sware and will not repent, Thou art a priest for ever after the order of Melchisedec:)
[/code]

Another advantage of running output through the Thor library is that we can perform post-processing to clean up the output (notice the use of Thor’s shell.set_color method):

We get a cleaner presentation:

[code]
_thor/bbl$ thor bbl:find "Thou art a priest"
[/code]

psalms 110:004 The LORD hath sworn, and will not repent, << Thou art a priest >> for ever after the order of Melchizedek.
hebrews 005:006 As he saith also in another place, << Thou art a priest >> for ever after the order of Melchisedec.
hebrews 007:017 For he testifieth, << Thou art a priest >> for ever after the order of Melchisedec.
hebrews 007:021 (For those priests were made without an oath; but this with an oath by him that said unto him, The Lord sware and will not repent, << Thou art a priest >> for ever after the order of Melchisedec:)

One thought on “Thor CLI KJV Bible Search Engine – part 2

  1. Pingback: Craft It Online » Thor CLI KJV Bible Search Engine – part 1

Leave a Reply

Your email address will not be published. Required fields are marked *