Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
peillis committed Dec 2, 2017
1 parent 3b7a067 commit e614cb5
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/elasticachex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ defmodule Elasticachex do
case length(values) do
6 ->
config_version = Enum.at(values, 1)
hosts =
values
|> Enum.at(2)
|> String.split(" ")
{:ok, get_hosts_list(hosts), config_version}
_ -> {:error, "Not recognized response from endpoint"}
hosts_string = Enum.at(values, 2)
{:ok, get_hosts_list(hosts_string), config_version}
_ ->
{:error, "Not recognized response from endpoint"}
end
end

defp get_hosts_list(hosts) do
Enum.reduce(hosts, [], fn(x, acc) ->
parts = String.split(x, "|")
["#{Enum.at(parts, 1)}:#{Enum.at(parts, 2)}" | acc]
end)
defp get_hosts_list(hosts_string) do
hosts_string
|> String.split(" ")
|> Enum.reduce([], fn(x, acc) ->
parts = String.split(x, "|")
["#{Enum.at(parts, 1)}:#{Enum.at(parts, 2)}" | acc]
end)
end

# The command to execute is different depending on versions
Expand Down

0 comments on commit e614cb5

Please sign in to comment.