class Unicafe::Lunch
Attributes
date[R]
name[R]
price[R]
Public Class Methods
format_data(data)
click to toggle source
# File lib/unicafe/lunch.rb, line 27 def self.format_data data data.entries.map{|date| self.format_lunches_of_date(date)}.flatten.compact end
format_lunch(date, data)
click to toggle source
# File lib/unicafe/lunch.rb, line 38 def self.format_lunch date, data self.new self.format_name(data), self.format_price(data), date rescue Exception => e end
format_lunches_of_date(data)
click to toggle source
# File lib/unicafe/lunch.rb, line 31 def self.format_lunches_of_date data date = self.parse_date data.title Nokogiri::HTML::DocumentFragment.parse(data.summary).children.map{ |lunch| self.format_lunch date, lunch } end
format_name(data)
click to toggle source
# File lib/unicafe/lunch.rb, line 48 def self.format_name data name_span = data.children.select{|elem| elem.name == 'span' && elem[:class] == "meal"}.first text_element = name_span.children.first text_element.to_s end
format_price(data)
click to toggle source
# File lib/unicafe/lunch.rb, line 54 def self.format_price data name_span = data.children.select{|elem| elem.name == 'span' && elem[:class] == "priceinfo"}.first text_element = name_span.children.first parser = ::Unicafe::PriceParser.new parser.parse text_element.to_s end
lunches_for_restaurant(id)
click to toggle source
# File lib/unicafe/lunch.rb, line 17 def self.lunches_for_restaurant id content = ::Net::HTTP.get(URI.parse("http://www.hyyravintolat.fi/rss/fin/#{id}/")) self.parse_data content end
new(name, price, date)
click to toggle source
# File lib/unicafe/lunch.rb, line 11 def initialize name, price, date @name = name @price = price @date = date end
parse_data(data)
click to toggle source
# File lib/unicafe/lunch.rb, line 22 def self.parse_data data parsed_data = Feedzirra::Feed.parse data self.format_data parsed_data end
parse_date(date)
click to toggle source
# File lib/unicafe/lunch.rb, line 43 def self.parse_date date require 'date' Date.parse date end