Sha256: e22e0e4264d711b80eebb2fb27f5ee4cb95d777727a5a83739a47b7dfbc3a2b8

Contents?: true

Size: 704 Bytes

Versions: 1

Compression:

Stored size: 704 Bytes

Contents

require 'json'

module SeatSelector
  class Parser
    class UnprocessableEntity < StandardError
    end

    def self.parse(json_str)
      begin
        obj = JSON.parse(json_str)
        seats = build_available_seats(obj.fetch("seats").values)
        layout = obj.fetch("venue").fetch("layout")
        rows = layout.fetch("rows")
        columns = layout.fetch("columns")
        
        venue = Venue.new(seats, rows, columns)
        Finder.new(venue)

      rescue StandardError
        raise UnprocessableEntity
      end
    end

    def self.build_available_seats(seats_args)
      seats_args.map { |args| Seat.new(args) }
    end
    private_class_method :build_available_seats
  
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seat_selector-0.1.1 lib/seat_selector/parser.rb