Class: GolfSwitch::CourseListCourse

Inherits:
Course
  • Object
show all
Defined in:
lib/golf_switch/course_list_course.rb

Instance Attribute Summary

Attributes inherited from Course

#adv_days, #cou, #cty, #dist, #id, #img, #img_base, #inside_days, #lat, #lon, #nm, #on_req, #promo, #rating, #s_ar, #s_cou, #s_reg, #st, #xid

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Course

#img_url

Constructor Details

#initialize(attributes = {}) ⇒ CourseListCourse

Returns a new instance of CourseListCourse.



3
4
5
6
7
8
9
# File 'lib/golf_switch/course_list_course.rb', line 3

def initialize(attributes={})
  attributes.each do |name, value|
    begin
      send("#{name}=", value)
    end
  end
end

Class Method Details

.parse_courses(response_hash) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/golf_switch/course_list_course.rb', line 10

def self.parse_courses(response_hash)
  courses= []

  if response_hash[:courses] && response_hash[:courses][:cl_course]
    if response_hash[:courses][:cl_course].is_a?(Array)
      response_hash[:courses][:cl_course].each do |course|
        begin
          courses  << CourseListCourse.new(course.merge(:img_base=>response_hash[:img_base]))
        end
      end
    elsif response_hash[:courses][:cl_course].is_a?(Hash)
      courses  << CourseListCourse.new(response_hash[:courses][:cl_course].merge(:img_base=>response_hash[:img_base]))
    end
  end
  courses
end