[ create a new paste ] login | about

Link: http://codepad.org/eVWLPmcC    [ raw code | fork ]

Ruby, pasted on Feb 11:
require 'csv'


module Reader

  module_function

  def load_hotels(filename)
    CSV.foreach(filename, :headers => true, :header_converters => :symbol) do |row|
      @hotels << Hotel.new(row)
    end
  end

end


class Hotel
  include Reader

  def initialize(hotel)
    @name            = hotel[:name]
    @rating          = hotel[:rating]
    @regular_weekday = hotel[:regular_weekday]
    @regular_weekend = hotel[:regular_weekend]
    @rewards_weekday = hotel[:rewards_weekday]
    @rewards_weekend = hotel[:rewards_weekend]
  end

end

class Customer


end

### Rspec test below:

describe "Reading from file" do 

  it "should open and read csv file" do
    hotels = Hotel.load_hotels("hotels.csv")
    hotels.should_not be_empty
  end

  it "should create model objects from file data"

end


Create a new paste based on this one


Comments: