Sha256: 9a7dec3e887df2c15f0aaf2c035a1a1c5ba6afec8309b390e363661013e95bf0

Contents?: true

Size: 913 Bytes

Versions: 1

Compression:

Stored size: 913 Bytes

Contents

class Menu
  # Scrapes for one dining hall, one day, one meal
  def initialize(dining_hall, date, meal)
    @date = date
    @meal = meal
    @dining_hall = dining_hall
    
    # Split dining hall tds array by date delimiter
    # Each child array contains menu titles and items for one day
    days_items = @dining_hall.tds.split do |td|
      begin
        DateTime.strptime(td, "%A, %B %d, %Y")
      rescue ArgumentError
        false
      else
        true
      end
    end
  
    @day_items = Hash[*days_items[DAYS.index(date.strftime("%A").downcase)].flatten]
  end
  
  def to_hash()
    # Return hash of items and titles
    @day_items
  end
  
  def to_s()
    str = "Menu for #{@meal} at #{@dining_hall.name.titlecase} on #{@date.strftime("%A, %B %d, %Y")}:\n"
    @day_items.each do |title, item|
      str += "#{title}: #{item}\n"
    end
    str.rstrip
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pennu-0.0.1 lib/classes/menu.rb