Class: Kat::App
- Inherits:
-
Object
- Object
- Kat::App
- Defined in:
- lib/kat/app.rb
Constant Summary collapse
- MIN_WIDTH =
80- CONFIG =
File.join ENV['HOME'], '.katrc'
Instance Attribute Summary collapse
-
#kat ⇒ Object
readonly
The
Kat::Searchsearch object. -
#options ⇒ Object
readonly
The app options hash.
-
#page ⇒ Object
The current page number (0-based).
Instance Method Summary collapse
-
#init_options(args = nil) ⇒ Object
Initialise the app’s options.
-
#init_search ⇒ Object
Initialise the
Kat::Searchobject with the query and it’s options. -
#initialize(args = ARGV) ⇒ App
constructor
Create a new
Kat::Appobject, using command-line switches as options by default. -
#main ⇒ Object
The main method.
Constructor Details
#initialize(args = ARGV) ⇒ App
Create a new Kat::App object, using command-line switches as options by default
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kat/app.rb', line 33 def initialize(args = ARGV) @kat = nil @page = 0 @window_width = 0 @show_info = !hide_info? @h = HighLine.new args init_search end |
Instance Attribute Details
#kat ⇒ Object (readonly)
The Kat::Search search object
25 26 27 |
# File 'lib/kat/app.rb', line 25 def kat @kat end |
#options ⇒ Object (readonly)
The app options hash
28 29 30 |
# File 'lib/kat/app.rb', line 28 def end |
#page ⇒ Object
The current page number (0-based)
22 23 24 |
# File 'lib/kat/app.rb', line 22 def page @page end |
Instance Method Details
#init_options(args = nil) ⇒ Object
Initialise the app’s options
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/kat/app.rb', line 47 def (args = nil) @args = case args when nil then [] when String then args.split else args end = load_config || {} Kat.(@args).tap do |o| .merge!(o) { |k, ov, nv| o["#{ k }_given".intern] ? nv : ov } end Kat::Colour.colour = [:colour] rescue NoMethodError => e = {} warn "Wrong config file format: #{ e }" end |
#init_search ⇒ Object
Initialise the Kat::Search object with the query and it’s options
69 70 71 72 73 |
# File 'lib/kat/app.rb', line 69 def init_search @kat ||= Kat.search @kat.query = @args.join(' ') @kat. = end |
#main ⇒ Object
The main method. Prints a list of options for categories, platforms, languages or times if the user has asked for them, otherwise will loop over the running method until the user quits (or there’s no results).
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/kat/app.rb', line 80 def main puts VERSION_STR Kat::Search.selects.select { |k, v| [v[:select]] }.tap do |lists| if lists.empty? while running; end else puts format_lists lists end end end |