Class: ClosestWeightliftingGem::Gym
- Inherits:
-
Object
- Object
- ClosestWeightliftingGem::Gym
- Defined in:
- lib/closest_weightlifting_gem/gym.rb
Constant Summary collapse
- @@all =
[]
- @@searches =
[]
Instance Attribute Summary collapse
-
#city ⇒ Object
Returns the value of attribute city.
-
#director ⇒ Object
Returns the value of attribute director.
-
#full_address ⇒ Object
Returns the value of attribute full_address.
-
#name ⇒ Object
Returns the value of attribute name.
-
#phone ⇒ Object
Returns the value of attribute phone.
-
#state ⇒ Object
Returns the value of attribute state.
-
#street ⇒ Object
Returns the value of attribute street.
-
#website ⇒ Object
Returns the value of attribute website.
-
#zipcode ⇒ Object
Returns the value of attribute zipcode.
Class Method Summary collapse
- .all ⇒ Object
- .count_by_state ⇒ Object
- .find_by_last_search ⇒ Object
- .find_by_name(input) ⇒ Object
- .find_by_state(state) ⇒ Object
- .last_search ⇒ Object
- .reset! ⇒ Object
- .searches ⇒ Object
- .weird_gyms ⇒ Object
Instance Method Summary collapse
- #add_attributes(gym_attributes) ⇒ Object
-
#initialize(gym_attributes) ⇒ Gym
constructor
A new instance of Gym.
Constructor Details
#initialize(gym_attributes) ⇒ Gym
Returns a new instance of Gym.
17 18 19 20 21 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 17 def initialize(gym_attributes) gym_attributes.each { |k,v| self.send(("#{k}="), v)} @@all << self end |
Instance Attribute Details
#city ⇒ Object
Returns the value of attribute city.
4 5 6 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 4 def city @city end |
#director ⇒ Object
Returns the value of attribute director.
4 5 6 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 4 def director @director end |
#full_address ⇒ Object
Returns the value of attribute full_address.
4 5 6 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 4 def full_address @full_address end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 4 def name @name end |
#phone ⇒ Object
Returns the value of attribute phone.
4 5 6 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 4 def phone @phone end |
#state ⇒ Object
Returns the value of attribute state.
4 5 6 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 4 def state @state end |
#street ⇒ Object
Returns the value of attribute street.
4 5 6 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 4 def street @street end |
#website ⇒ Object
Returns the value of attribute website.
4 5 6 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 4 def website @website end |
#zipcode ⇒ Object
Returns the value of attribute zipcode.
4 5 6 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 4 def zipcode @zipcode end |
Class Method Details
.all ⇒ Object
35 36 37 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 35 def self.all @@all end |
.count_by_state ⇒ Object
74 75 76 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 74 def self.count_by_state self.all.inject(Hash.new(0)) { |total, gym| total[gym.state] += 1 ; total } end |
.find_by_last_search ⇒ Object
69 70 71 72 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 69 def self.find_by_last_search last_search = @@searches.last self.send(last_search[:method], last_search[:value]) end |
.find_by_name(input) ⇒ Object
57 58 59 60 61 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 57 def self.find_by_name(input) self.searches << { method: __method__, value: input } self.all.find_all { |gym| gym.name.upcase.include?(input.upcase) } end |
.find_by_state(state) ⇒ Object
63 64 65 66 67 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 63 def self.find_by_state(state) self.searches << { method: __method__, value: state } self.all.find_all { |gym| gym.state == state.upcase } end |
.last_search ⇒ Object
39 40 41 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 39 def self.last_search @@searches.last end |
.reset! ⇒ Object
47 48 49 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 47 def self.reset! self.all.clear end |
.searches ⇒ Object
43 44 45 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 43 def self.searches @@searches end |
.weird_gyms ⇒ Object
51 52 53 54 55 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 51 def self.weird_gyms self.all.find_all do |g| g.phone.nil? || g.street.nil? || g.name.nil? || g.city.nil? end end |
Instance Method Details
#add_attributes(gym_attributes) ⇒ Object
23 24 25 |
# File 'lib/closest_weightlifting_gem/gym.rb', line 23 def add_attributes(gym_attributes) gym_attributes.each { |k,v| self.send(("#{k}="), v)} end |