diff --git a/.gitignore b/.gitignore index 45dc04c..8d7fc28 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,5 @@ erl_crash.dump # Ignore package tarball (built via "mix hex.build"). sherdog_parser-*.tar -.iex.exs \ No newline at end of file +.vscode/ +.iex.exs diff --git a/lib/sherdog_parser/event_parser.ex b/lib/sherdog_parser/event_parser.ex index e75a326..d8ff8a8 100644 --- a/lib/sherdog_parser/event_parser.ex +++ b/lib/sherdog_parser/event_parser.ex @@ -70,6 +70,11 @@ defmodule SherdogParser.EventParser do {"td", _, [_, _, time]} ] = Floki.find(html, "div.module.fight_card > div.content.event > div.footer td") + method = + method + |> String.trim() + |> Fight.method() + %Fight{ fighter_a_id: fighter_a_id, fighter_a_name: fighter_a_name, @@ -78,7 +83,7 @@ defmodule SherdogParser.EventParser do result: fighter_a_result |> Fight.get_result(), referee: referee |> String.trim(), round: round |> String.trim() |> String.to_integer(), - method: Fight.method(method), + method: method, time: Fight.parse_time(time) } end diff --git a/lib/sherdog_parser/fight.ex b/lib/sherdog_parser/fight.ex index 1a8ce3f..30cff90 100644 --- a/lib/sherdog_parser/fight.ex +++ b/lib/sherdog_parser/fight.ex @@ -20,7 +20,7 @@ defmodule SherdogParser.Fight do field(:event_date, Date.t()) end - def method("Draw"), do: "" + def method("Draw"), do: {"Draw", nil} def method(m) do [_, major, minor] = @@ -33,10 +33,25 @@ defmodule SherdogParser.Fight do def get_result("win"), do: :a def get_result("loss"), do: :b def get_result("draw"), do: :draw + def get_result("NC"), do: :no_contest + def get_result("nc"), do: :no_contest def parse_time(time) do [minute, second] = time |> String.trim() |> String.split(":") - {:ok, time} = Time.new(0, minute |> String.to_integer(), second |> String.to_integer()) + + {:ok, time} = + Time.new( + 0, + time_part_to_integer(minute), + time_part_to_integer(second) + ) + time end + + defp time_part_to_integer(""), do: 0 + + defp time_part_to_integer(time_part) + when is_binary(time_part), + do: String.to_integer(time_part) end