Class: Gas_station

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, address:, price:, detail_url:) ⇒ Gas_station

Returns a new instance of Gas_station.



5
6
7
8
9
10
# File 'lib/gas_station.rb', line 5

def initialize(name:,address:,price:, detail_url:)
    @name = name 
    @address = address 
    @price = price 
    @detail_url = detail_url
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



3
4
5
# File 'lib/gas_station.rb', line 3

def address
  @address
end

#detail_urlObject

Returns the value of attribute detail_url.



3
4
5
# File 'lib/gas_station.rb', line 3

def detail_url
  @detail_url
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/gas_station.rb', line 3

def name
  @name
end

#new_arrayObject

Returns the value of attribute new_array.



3
4
5
# File 'lib/gas_station.rb', line 3

def new_array
  @new_array
end

#priceObject

Returns the value of attribute price.



3
4
5
# File 'lib/gas_station.rb', line 3

def price
  @price
end

#ratingObject

Returns the value of attribute rating.



3
4
5
# File 'lib/gas_station.rb', line 3

def rating
  @rating
end

Class Method Details

.allObject



27
28
29
# File 'lib/gas_station.rb', line 27

def self.all 
    @@all.sort_by{|gas_station| gas_station.price }
end

.create_gas_station_from_data(array_of_gas_station) ⇒ Object



13
14
15
16
17
18
# File 'lib/gas_station.rb', line 13

def self.create_gas_station_from_data(array_of_gas_station) 
    array_of_gas_station.each do |gas_station|
         gas_object =self.new(gas_station) 
         @@all << gas_object if gas_object.price
    end
end

Instance Method Details

#add_more_info(data) ⇒ Object



21
22
23
24
# File 'lib/gas_station.rb', line 21

def add_more_info(data)
    the_gas_station = self
    data.each {|key,val| the_gas_station.send("#{key}=",val) }
end