Sha256: 9ab25362986bd551cdcd95b690a535ffec9ba15b3a881cca09f0b6d680307a31

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 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 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 hidden
      @data['hidden']
    end
    alias :hidden? :hidden

    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 slots
      @slots ||= @data['slots'].map { |slot| Slot.new(slot) }
    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

2 entries across 2 versions & 1 rubygems

Version Path
booking_locations-0.15.0 lib/booking_locations/location.rb
booking_locations-0.14.0 lib/booking_locations/location.rb