class BostonFoodTrucks::Truck

Constants

URL

Attributes

day[R]
location[R]
meal[R]
name[R]

Public Class Methods

all() click to toggle source
# File lib/boston_food_trucks/truck.rb, line 33
def all
  food_trucks
end
in(location, day = day_of_week) click to toggle source
# File lib/boston_food_trucks/truck.rb, line 25
def in(location, day = day_of_week)
  food_trucks.select { |truck| truck.location.include?(location) && truck.day == day }
end
new(name, day, meal, location) click to toggle source
# File lib/boston_food_trucks/truck.rb, line 7
def initialize(name, day, meal, location)
  @name = name
  @day = day
  @meal = meal
  @location = location
end
today() click to toggle source
# File lib/boston_food_trucks/truck.rb, line 29
def today
  food_trucks.select { |truck| truck.day == day_of_week }
end

Private Class Methods

day_of_week() click to toggle source
# File lib/boston_food_trucks/truck.rb, line 62
def day_of_week
  Date::DAYNAMES[Date.today.wday]
end
doc() click to toggle source
# File lib/boston_food_trucks/truck.rb, line 58
def doc
  Nokogiri::HTML(open(URL).read)
end
food_trucks() click to toggle source
# File lib/boston_food_trucks/truck.rb, line 39
def food_trucks
  @@food_trucks ||= load_from_document
end
load_from_document() click to toggle source
# File lib/boston_food_trucks/truck.rb, line 43
def load_from_document
  result = []
  doc.css('tr.trFoodTrucks').each do |row|
    name = row.css('td.com').text
    day = row.css('td.dow').text
    meal = row.css('td.tod').text
    row.css('td.loc script').remove
    location = row.css('td.loc').text

    result << BostonFoodTrucks::Truck.new(name, day, meal, location)
  end

  result
end

Public Instance Methods

to_h() click to toggle source
# File lib/boston_food_trucks/truck.rb, line 18
def to_h
  { name: name, meal: meal, location: location }
end
to_s() click to toggle source
# File lib/boston_food_trucks/truck.rb, line 14
def to_s
  "#{name} for #{meal} @ #{location}"
end