Class: ClosestWeightliftingGem::Gym

Inherits:
Object
  • Object
show all
Defined in:
lib/closest_weightlifting_gem/gym.rb

Constant Summary collapse

@@all =
[]
@@searches =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#cityObject

Returns the value of attribute city.



4
5
6
# File 'lib/closest_weightlifting_gem/gym.rb', line 4

def city
  @city
end

#directorObject

Returns the value of attribute director.



4
5
6
# File 'lib/closest_weightlifting_gem/gym.rb', line 4

def director
  @director
end

#full_addressObject

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

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/closest_weightlifting_gem/gym.rb', line 4

def name
  @name
end

#phoneObject

Returns the value of attribute phone.



4
5
6
# File 'lib/closest_weightlifting_gem/gym.rb', line 4

def phone
  @phone
end

#stateObject

Returns the value of attribute state.



4
5
6
# File 'lib/closest_weightlifting_gem/gym.rb', line 4

def state
  @state
end

#streetObject

Returns the value of attribute street.



4
5
6
# File 'lib/closest_weightlifting_gem/gym.rb', line 4

def street
  @street
end

#websiteObject

Returns the value of attribute website.



4
5
6
# File 'lib/closest_weightlifting_gem/gym.rb', line 4

def website
  @website
end

#zipcodeObject

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

.allObject



35
36
37
# File 'lib/closest_weightlifting_gem/gym.rb', line 35

def self.all
  @@all
end

.count_by_stateObject



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_searchObject



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_searchObject



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

.searchesObject



43
44
45
# File 'lib/closest_weightlifting_gem/gym.rb', line 43

def self.searches
  @@searches
end

.weird_gymsObject



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