Source: maps/places/PlaceDetailParser.js


/**
 * @class
 * Parses information from the place object returned from the Google Places service.
 * This class acts as a wrapper around the Google place object
 * and provides methods to parse information from the wrapped object.
 * 
 * @constructor
 * @param {google.maps.places.PlaceResult} place  The place we want the details from.
 */
lucid.maps.places.PlaceDetailParser = function( place )
{
	
	/**
	 * Check if the place has been given a rating.
	 * 
	 * @return {boolean}  True if the place has a rating.
	 */
	this.hasRating = function()
	{
		return (typeof place.rating === "number");
	};
	
	/**
	 * Get the rating given to the place.
	 * This may be undefined. Use the hasRating function to test if the rating exists.
	 * 
	 * @return {number}  The place's rating.
	 */
	this.getRating = function()
	{
		return place.rating;
	};
	
	/**
	 * Check if the place has defined its opening hours.
	 * 
	 * @return {boolean}  True if the place has opening hours defined.
	 */
	this.hasOpeningHours = function()
	{
		return (typeof place.opening_hours !== "undefined") && (typeof place.opening_hours.periods !== "undefined") && (typeof place.opening_hours.periods.length === "number");
	};
	
	/**
	 * Get the opening hours for the current day of the week.
	 * This may be undefined. Use the hasOpeningHours function to test if the opening hours exist.
	 * 
	 * @return {string}  The opening hours for the current day of the week.
	 */
	this.getOpeningHoursToday = function()
	{
		return this.getOpeningHours( new Date().getDay() );
	};
	
	/**
	 * Get the opening hours for the specified day of the week.
	 * This may be undefined. Use the hasOpeningHours function to test if the opening hours exist.
	 * 
	 * @param {number} day  The zero-based index of the day of the week. With 0 being Monday.
	 * @return {string}  The opening hours for the current day of the week.
	 */
	this.getOpeningHours = function( day )
	{
		var periods = [];
		for (var i=0; i<place.opening_hours.periods.length; i++)
		{
			if (place.opening_hours.periods[i].open.day == day)
			{
				periods[periods.length] = place.opening_hours.periods[i];
			}
		}
		
		var openingHoursText;
		if (periods.length > 0)
		{
			openingHoursText = "Open ";
			for (var i=0; i<periods.length; i++)
			{
				if (i > 0)
				{
					openingHoursText += ", ";
				}
				openingHoursText += periods[i].open.time + " - " + periods[i].close.time;
			}
		}
		else
		{
			openingHoursText = "Closed";
		}
		
		return openingHoursText;
	};
	
	// TODO Parse "reviews[n].text"
};