Class: RfcReader::Command
- Inherits:
-
Thor
- Object
- Thor
- RfcReader::Command
- Defined in:
- lib/rfc_reader/command.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#help(command = nil) ⇒ Integer
Exit code.
-
#library ⇒ Integer
Exit code.
-
#recent ⇒ Integer
Exit code.
-
#search(term) ⇒ Integer
Exit code.
-
#version ⇒ Integer
Exit code.
Class Method Details
.exit_on_failure? ⇒ Boolean
14 |
# File 'lib/rfc_reader/command.rb', line 14 def self.exit_on_failure? = true |
Instance Method Details
#help(command = nil) ⇒ Integer
Returns exit code.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rfc_reader/command.rb', line 18 def help(command = nil) unless command puts <<~DESCRIPTION >>> rfc-reader This command downloads the plaintext version of RFCs from rfc-editor.org so that they can be read at the command line. The last 100 downloaded RFCs are saved locally so that they can be read later on without the need for an internet connection. DESCRIPTION end super SUCCESS end |
#library ⇒ Integer
Returns exit code.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rfc_reader/command.rb', line 88 def library rfc_catalog = Library.catalog if rfc_catalog.empty? warn <<~MESSAGE No RFCs are currently saved in the library. Try using the `search` or `recent` commands to download some RFCs first. MESSAGE return FAILURE end all_titles = rfc_catalog.map { _1[:title] } title = Terminal.choose("Choose an RFC to read:", all_titles) rfc = rfc_catalog.find { _1[:title] == title } content = Library.load_document(**rfc) Terminal.page(content) SUCCESS end |
#recent ⇒ Integer
Returns exit code.
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rfc_reader/command.rb', line 67 def recent recent_results = Recent.list if recent_results.empty? warn "Error: Empty recent RFC list from rfc-editor.org RSS feed" return FAILURE end title = Terminal.choose("Choose an RFC to read:", recent_results.keys) url = recent_results.fetch(title) content = Library.download_document(title: title, url: url) Terminal.page(content) SUCCESS end |
#search(term) ⇒ Integer
Returns exit code.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rfc_reader/command.rb', line 46 def search(term) search_results = Search.search_by(term: term) if search_results.empty? warn "No search results for: #{term}" return FAILURE end title = Terminal.choose("Choose an RFC to read:", search_results.keys) url = search_results.fetch(title) content = Library.download_document(title: title, url: url) Terminal.page(content) SUCCESS end |
#version ⇒ Integer
Returns exit code.
107 108 109 110 |
# File 'lib/rfc_reader/command.rb', line 107 def version puts VERSION SUCCESS end |