Class: Gooby::Course

Inherits:
GoobyObject show all
Defined in:
lib/gooby_course.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GoobyKernel

#character_align, #default_delimiter, #invalid_altitude, #invalid_heartbeat, #invalid_latitude, #invalid_longitude, #invalid_time, #project_author, #project_copyright, #project_date, #project_embedded_comment, #project_license, #project_name, #project_version_number, #project_year, #read_as_ascii_lines, #read_lines, #strip_lines, #tokenize

Constructor Details

#initialize(yaml_csv) ⇒ Course

Returns a new instance of Course.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gooby_course.rb', line 15

def initialize(yaml_csv)
  @name, @distance = '', 0.0
  @point_numbers, @points, @bad_points = Array.new, Array.new, Array.new
  @points_hash, @matched_points = Hash.new, Hash.new
  tokens    = yaml_csv.split(',')
  @name     = tokens[0]      if tokens.size > 0
  @distance = tokens[1].to_f if tokens.size > 1 
  if tokens.size > 2
    index = 0
    tokens.each { |tok|
      index = index + 1
      if (index > 2)
        poi = Configuration.get_config.get_poi(tok)
        if (poi)
          poi.number     =  "#{tok}"
          @point_numbers << "#{tok}"
          @points        << poi
          @points_hash["#{tok}"] = poi
        else
          @bad_points << tok
        end
      end
    }
  end 
end

Instance Attribute Details

#distanceObject

Returns the value of attribute distance.



13
14
15
# File 'lib/gooby_course.rb', line 13

def distance
  @distance
end

#nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/gooby_course.rb', line 13

def name
  @name
end

#point_numbersObject

Returns the value of attribute point_numbers.



13
14
15
# File 'lib/gooby_course.rb', line 13

def point_numbers
  @point_numbers
end

#pointsObject

Returns the value of attribute points.



13
14
15
# File 'lib/gooby_course.rb', line 13

def points
  @points
end

Instance Method Details

#display_matchesObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gooby_course.rb', line 53

def display_matches
  puts ''
  calculate_matches
  @point_numbers.each { |num|
    point  = @points_hash["#{num}"]
    mpoint = @matched_points["#{num}"]
    puts ''
    puts "  Course Point:    #{point.to_formatted_string}"   if point
    puts "    Matched Point: #{mpoint.to_formatted_string}"  if mpoint
  }
  puts ''
end

#dumpObject



74
75
76
77
78
# File 'lib/gooby_course.rb', line 74

def dump
  puts "Course:   #{@name}"
  puts "Distance: #{@distance}"
  points.each { |pt| puts pt } #{@points.size} errors: #{has_errors}" 
end

#has_errorsObject



41
42
43
# File 'lib/gooby_course.rb', line 41

def has_errors
  (@bad_points.size > 0) ? true : false
end

#matched(number, point) ⇒ Object



45
46
47
# File 'lib/gooby_course.rb', line 45

def matched(number, point)
  @matched_points["#{number}"] = point if point
end

#matched?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/gooby_course.rb', line 49

def matched?
  (@matched_points.size == @point_numbers.size) ? true : false
end

#resetObject



66
67
68
# File 'lib/gooby_course.rb', line 66

def reset
  @matched_points = Hash.new
end

#to_sObject



70
71
72
# File 'lib/gooby_course.rb', line 70

def to_s
  "#{@name} #{@distance}  points: #{@points.size} errors: #{has_errors}" 
end