Class: SocialFramework::RouteHelper::RouteStrategyDefault

Inherits:
RouteStrategy
  • Object
show all
Defined in:
app/helpers/social_framework/route_helper.rb

Overview

Contains the methods to match routes

Constant Summary collapse

RATIO_OF_EARTH =
6500000

Instance Method Summary collapse

Instance Method Details

#compare_routes(principal_route, secondary_route) ⇒ Object

Compare the routes to verify if are compatible

Params:
principal_route

Route who gives a lift

secondary_route

Route who hitchhike

Returns Hash with information of compatibility and necessary distances



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/helpers/social_framework/route_helper.rb', line 28

def compare_routes(principal_route, secondary_route)

  principal_accepted = principal_accepted_deviation(principal_route, secondary_route)

  result = {compatible: false, principal_route: {deviation: :none,
      distance: 0}, secondary_route: {deviation: :none, distance: 0}}

  if(principal_accepted[:accept] == :both)
    result[:compatible] = true
    result[:principal_route][:deviation] = :both
    result[:principal_route][:distance] = principal_accepted[:distance]
  else
    secondary_origin, secondary_destiny, secondary_accepted =
          condictions_secondary_deviation(principal_route, secondary_route, principal_accepted)

    if(secondary_origin)
      build_result(result, true, :destiny, principal_accepted[:distance_destiny],
                            :origin, secondary_accepted[:distance_origin])
    elsif(secondary_destiny)
      build_result(result, true, :origin, principal_accepted[:distance_origin],
                            :destiny, secondary_accepted[:distance_destiny])
    end
  end

  return result
end