Sha256: 08aa0aceece28136fb2e50cf1424f873ab78c4ea51710cdc21f74d5b3479bec0

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

require 'ostruct'
require 'global_id'

module BookingLocations
  class Location
    include GlobalID::Identification

    def initialize(data)
      @data = data
    end

    def self.find(id)
      BookingLocations.find(id)
    end

    def id
      @data['uid']
    end

    def name
      @data['name']
    end

    def title
      @data['title']
    end

    def address
      @data['address']
    end

    def online_booking_twilio_number
      @data['online_booking_twilio_number']
    end

    def online_booking_reply_to
      @data['online_booking_reply_to']
    end

    def online_booking_weekends
      @data['online_booking_weekends']
    end
    alias :online_booking_weekends? :online_booking_weekends

    def hidden
      @data['hidden']
    end
    alias :hidden? :hidden

    def realtime
      @data['realtime']
    end
    alias :realtime? :realtime

    def locations
      @locations ||= @data['locations'].map { |child_data| Location.new(child_data) }
    end

    def guiders
      @guiders ||= @data['guiders'].map { |guider| OpenStruct.new(guider) }
    end

    def guider_name_for(guider_id)
      guiders.find { |guider| guider.id == guider_id }.name
    end

    def location_for(location_id)
      return self if id == location_id

      locations.find { |location| location.id == location_id }
    end

    def name_for(location_id)
      found = location_for(location_id)
      found ? found.name : ''
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
booking_locations-0.22.0 lib/booking_locations/location.rb