Skip to content

Instantly share code, notes, and snippets.

@brooksreese
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save brooksreese/a7533da01f410ed623df to your computer and use it in GitHub Desktop.

Select an option

Save brooksreese/a7533da01f410ed623df to your computer and use it in GitHub Desktop.

Revisions

  1. brooksreese revised this gist May 21, 2014. 1 changed file with 0 additions and 12 deletions.
    12 changes: 0 additions & 12 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -38,18 +38,6 @@
    end
    end

    ##################################
    # refactored case statement to if
    ##################################
    if location.services.length != 0 # zero would mean no services were selected
    if location.services.length == 1

    else
    marker.picture({ :url => markers[:all], :width => 32, :height => 32 })
    end
    end


    marker.infowindow "<b>#{location.name}</b>
    <br/><i>#{location.address}</i>
    <br/><i>#{location.city} #{location.state}., #{location.zip}</i>
  2. brooksreese created this gist May 21, 2014.
    59 changes: 59 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    def set_gmap_markers
    markers = {
    :ddtcs => ActionController::Base.helpers.asset_path('marker_DDTCS.png'),
    :chms => ActionController::Base.helpers.asset_path('marker_CHMS.png'),
    :all => ActionController::Base.helpers.asset_path('marker_CHMS-DDTCS.png')
    }

    @hash = Gmaps4rails.build_markers(@locations) do |location, marker|
    marker.lat location.latitude
    marker.lng location.longitude

    ##################################
    # code before refactoring
    ##################################
    # if location.services.length == 2
    # marker.picture({ :url => markers[:all], :width => 32, :height => 32 })
    # end

    # if location.services.length == 1 && location.services[0].name == 'CHMS'
    # marker.picture({ :url => markers[:chms], :width => 32, :height => 32 })
    # end

    # if location.services.length == 1 && location.services[0].name == 'DDTCS'
    # marker.picture({ :url => markers[:ddtcs], :width => 32, :height => 32 })
    # end

    ##################################
    # code after refactoring
    ##################################
    case location.services.length
    when 2
    marker.picture({ :url => markers[:all], :width => 32, :height => 32 })
    when 1
    if location.services[0].name == 'CHMS'
    marker.picture({ :url => markers[:chms], :width => 32, :height => 32 })
    else
    marker.picture({ :url => markers[:ddtcs], :width => 32, :height => 32 })
    end
    end

    ##################################
    # refactored case statement to if
    ##################################
    if location.services.length != 0 # zero would mean no services were selected
    if location.services.length == 1

    else
    marker.picture({ :url => markers[:all], :width => 32, :height => 32 })
    end
    end


    marker.infowindow "<b>#{location.name}</b>
    <br/><i>#{location.address}</i>
    <br/><i>#{location.city} #{location.state}., #{location.zip}</i>
    <p/>#{location.services.map{|service| service.name }.join(', ') }
    <p/><a href=\"#{location_path(location)}\">Location Details</a>"
    end
    end