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.



2
3
4
# File 'lib/closest_weightlifting_gem/gym.rb', line 2

def city
  @city
end

#coachObject

Returns the value of attribute coach.



2
3
4
# File 'lib/closest_weightlifting_gem/gym.rb', line 2

def coach
  @coach
end

#directorObject

Returns the value of attribute director.



2
3
4
# File 'lib/closest_weightlifting_gem/gym.rb', line 2

def director
  @director
end

#full_addressObject

Returns the value of attribute full_address.



2
3
4
# File 'lib/closest_weightlifting_gem/gym.rb', line 2

def full_address
  @full_address
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/closest_weightlifting_gem/gym.rb', line 2

def name
  @name
end

#phoneObject

Returns the value of attribute phone.



2
3
4
# File 'lib/closest_weightlifting_gem/gym.rb', line 2

def phone
  @phone
end

#stateObject

Returns the value of attribute state.



2
3
4
# File 'lib/closest_weightlifting_gem/gym.rb', line 2

def state
  @state
end

#streetObject

Returns the value of attribute street.



2
3
4
# File 'lib/closest_weightlifting_gem/gym.rb', line 2

def street
  @street
end

#usaw_urlObject

Returns the value of attribute usaw_url.



2
3
4
# File 'lib/closest_weightlifting_gem/gym.rb', line 2

def usaw_url
  @usaw_url
end

#websiteObject

Returns the value of attribute website.



2
3
4
# File 'lib/closest_weightlifting_gem/gym.rb', line 2

def website
  @website
end

#zipcodeObject

Returns the value of attribute zipcode.



2
3
4
# File 'lib/closest_weightlifting_gem/gym.rb', line 2

def zipcode
  @zipcode
end

Class Method Details

.allObject



31
32
33
# File 'lib/closest_weightlifting_gem/gym.rb', line 31

def self.all
  @@all
end

.count_by_stateObject



67
68
69
# File 'lib/closest_weightlifting_gem/gym.rb', line 67

def self.count_by_state
  self.all.inject(Hash.new(0)) { |total, gym| total[gym.state] += 1 ; total }
end

.find_by_name(input) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/closest_weightlifting_gem/gym.rb', line 53

def self.find_by_name(input)
  self.searches << { method: __method__, value: input }

  select_few = self.all.select do |gym|
    gym.name.upcase.include?(input.upcase)
  end
end

.find_by_state(state) ⇒ Object



61
62
63
64
65
# File 'lib/closest_weightlifting_gem/gym.rb', line 61

def self.find_by_state(state)
  self.searches << { method: __method__, value: state }
  
  self.all.find_all { |gym| gym.state == state.upcase }
end

.last_searchObject



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

def self.last_search
  @@searches.last
end

.reset!Object



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

def self.reset!
  self.all.clear
end

.searchesObject



39
40
41
# File 'lib/closest_weightlifting_gem/gym.rb', line 39

def self.searches
  @@searches
end

.weird_gymsObject



47
48
49
50
51
# File 'lib/closest_weightlifting_gem/gym.rb', line 47

def self.weird_gyms
  self.all.find_all do |g| 
    g.phone == nil || g.street == nil || g.name == 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