Class: GymFinder::Cli
- Inherits:
-
Object
- Object
- GymFinder::Cli
- Defined in:
- lib/gym_finder/cli.rb
Instance Method Summary collapse
-
#initialize(gyms: [], courts: [], hours: [], weekend: false, weekday: false, only_available: true, username: , password: ) ⇒ Cli
constructor
A new instance of Cli.
- #perform ⇒ Object
Constructor Details
#initialize(gyms: [], courts: [], hours: [], weekend: false, weekday: false, only_available: true, username: , password: ) ⇒ Cli
Returns a new instance of Cli.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gym_finder/cli.rb', line 9 def initialize( gyms: [], courts: [], hours: [], weekend: false, weekday: false, only_available: true, username: ENV['GYM_FINDER_USERNAME'], password: ENV['GYM_FINDER_PASSWORD'] ) bind = binding local_variables.each do |variable| instance_variable_set( "@#{variable}", bind.local_variable_get(variable) ) end validate! @client = Client.new(username: username, password: password) @gym_filter = lambda { |gym| gyms.empty? ? true : gyms.any? { |name| gym.name.include?(name) } } @court_filter = lambda { |court| courts.empty? ? true : courts.any? { |name| court.name.include?(name) } } @date_filter = lambda { |date| return true unless weekend ^ weekday return date.sunday? || date.saturday? if weekend return !date.sunday? && !date.sunday if weekday } end |
Instance Method Details
#perform ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/gym_finder/cli.rb', line 41 def perform results = @client.fetch( gym_filter: @gym_filter, court_filter: @court_filter, date_filter: @date_filter ) results = PostProcessor.new(results).available.slots if @only_available results = PostProcessor.new(results).hour_list(hour_list).slots unless @hours.empty? results end |