Class: GolfSwitch::CourseInfoCourse

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

Instance Attribute Summary collapse

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 = {}) ⇒ CourseInfoCourse

Returns a new instance of CourseInfoCourse.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/golf_switch/course_info_course.rb', line 8

def initialize(attributes={})
  @yard_ages= []
  @pars = []
  @handicaps = []
  @imgs = []
  attributes.each do |name, value|
    begin
      if name.to_s=="imgs"
        parse_images(value)
      elsif  name.to_s =="cxl_policy"
        @cxl_policy = GolfSwitch::CoursePolicy.new(value)
      elsif name.to_s == "score_card"
        @yard_ages = parse_score_card((value[:yardages][:yardage] rescue nil))
        @pars = parse_score_card((value[:pars][:par] rescue nil))
        @handicaps  =parse_score_card((value[:handicaps][:handicap] rescue nil))
      else
        send("#{name}=", value)
      end
    rescue
      puts "Add #{name} as accessor in Corse Info Course"
    end
  end
  set_course_image

end

Instance Attribute Details

#addr1Object

Returns the value of attribute addr1.



3
4
5
# File 'lib/golf_switch/course_info_course.rb', line 3

def addr1
  @addr1
end

#allow_playersObject

Returns the value of attribute allow_players.



4
5
6
# File 'lib/golf_switch/course_info_course.rb', line 4

def allow_players
  @allow_players
end

#cc_allowObject

Returns the value of attribute cc_allow.



4
5
6
# File 'lib/golf_switch/course_info_course.rb', line 4

def cc_allow
  @cc_allow
end

#currObject

Returns the value of attribute curr.



3
4
5
# File 'lib/golf_switch/course_info_course.rb', line 3

def curr
  @curr
end

#cxl_policyObject

Returns the value of attribute cxl_policy.



5
6
7
# File 'lib/golf_switch/course_info_course.rb', line 5

def cxl_policy
  @cxl_policy
end

#designerObject

Returns the value of attribute designer.



4
5
6
# File 'lib/golf_switch/course_info_course.rb', line 4

def designer
  @designer
end

#dress_codeObject

Returns the value of attribute dress_code.



5
6
7
# File 'lib/golf_switch/course_info_course.rb', line 5

def dress_code
  @dress_code
end

#from_priceObject

Returns the value of attribute from_price.



3
4
5
# File 'lib/golf_switch/course_info_course.rb', line 3

def from_price
  @from_price
end

#greensObject

Returns the value of attribute greens.



4
5
6
# File 'lib/golf_switch/course_info_course.rb', line 4

def greens
  @greens
end

#handicapsObject

Returns the value of attribute handicaps.



6
7
8
# File 'lib/golf_switch/course_info_course.rb', line 6

def handicaps
  @handicaps
end

#has_net_ratesObject

Returns the value of attribute has_net_rates.



5
6
7
# File 'lib/golf_switch/course_info_course.rb', line 5

def has_net_rates
  @has_net_rates
end

#has_tradeObject

Returns the value of attribute has_trade.



5
6
7
# File 'lib/golf_switch/course_info_course.rb', line 5

def has_trade
  @has_trade
end

#holesObject

Returns the value of attribute holes.



4
5
6
# File 'lib/golf_switch/course_info_course.rb', line 4

def holes
  @holes
end

#imgsObject

Returns the value of attribute imgs.



4
5
6
# File 'lib/golf_switch/course_info_course.rb', line 4

def imgs
  @imgs
end

#max_reward_pointsObject

Returns the value of attribute max_reward_points.



3
4
5
# File 'lib/golf_switch/course_info_course.rb', line 3

def max_reward_points
  @max_reward_points
end

#noteObject

Returns the value of attribute note.



3
4
5
# File 'lib/golf_switch/course_info_course.rb', line 3

def note
  @note
end

#parsObject

Returns the value of attribute pars.



6
7
8
# File 'lib/golf_switch/course_info_course.rb', line 6

def pars
  @pars
end

#payment_termsObject

Returns the value of attribute payment_terms.



5
6
7
# File 'lib/golf_switch/course_info_course.rb', line 5

def payment_terms
  @payment_terms
end

#rating_cntObject

Returns the value of attribute rating_cnt.



3
4
5
# File 'lib/golf_switch/course_info_course.rb', line 3

def rating_cnt
  @rating_cnt
end

#score_cardObject

Returns the value of attribute score_card.



5
6
7
# File 'lib/golf_switch/course_info_course.rb', line 5

def score_card
  @score_card
end

#servicesObject

Returns the value of attribute services.



4
5
6
# File 'lib/golf_switch/course_info_course.rb', line 4

def services
  @services
end

#short_promoObject

Returns the value of attribute short_promo.



3
4
5
# File 'lib/golf_switch/course_info_course.rb', line 3

def short_promo
  @short_promo
end

#to_priceObject

Returns the value of attribute to_price.



3
4
5
# File 'lib/golf_switch/course_info_course.rb', line 3

def to_price
  @to_price
end

#yard_agesObject

Returns the value of attribute yard_ages.



6
7
8
# File 'lib/golf_switch/course_info_course.rb', line 6

def yard_ages
  @yard_ages
end

#year_builtObject

Returns the value of attribute year_built.



4
5
6
# File 'lib/golf_switch/course_info_course.rb', line 4

def year_built
  @year_built
end

#zipObject

Returns the value of attribute zip.



3
4
5
# File 'lib/golf_switch/course_info_course.rb', line 3

def zip
  @zip
end

Class Method Details

.parse_course(response_hash) ⇒ Object



68
69
70
# File 'lib/golf_switch/course_info_course.rb', line 68

def self.parse_course(response_hash)
  CourseInfoCourse.new(response_hash[:course].merge(:img_base=>response_hash[:img_base]))
end

Instance Method Details

#images(protocol = "https") ⇒ Object



72
73
74
75
76
77
78
# File 'lib/golf_switch/course_info_course.rb', line 72

def images(protocol="https")
  images = []
  self.imgs.each do |img|
    images << build_url(img,protocol)
  end
  images
end

#no_of_allowed_playerObject



64
65
66
# File 'lib/golf_switch/course_info_course.rb', line 64

def no_of_allowed_player
  @allow_players.split("").count{|p| p=='Y'}
end

#parse_images(imgs) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/golf_switch/course_info_course.rb', line 54

def parse_images(imgs)
  if imgs[:img].is_a?(Array)
    imgs[:img].each do |img|
      @imgs << img
    end
  elsif imgs[:img].is_a?(String)
    @imgs << imgs[:img]
  end
end

#parse_score_card(scores) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/golf_switch/course_info_course.rb', line 42

def parse_score_card(scores)
  score_card =[]
  if scores.is_a?(Array)
    scores.each do |score|
      score_card << GolfSwitch::ScoreCard.new(score)
    end
  elsif scores.is_a?(Hash)
    score_card << GolfSwitch::ScoreCard.new(scores)
  end
  score_card
end

#set_course_imageObject



33
34
35
36
37
38
39
40
# File 'lib/golf_switch/course_info_course.rb', line 33

def set_course_image
  unless @imgs.grep(/overview/).blank?
    @img = @imgs.grep(/overview/).first
  else
    @img = @imgs[0]
  end

end