September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,7 +1,7 @@
|
|||
defmodule Align do
|
||||
def columns(text, alignment) do
|
||||
fieldsbyrow = String.split(text, "\n", trim: true)
|
||||
|> Enum.map(fn line -> String.split(line, "$", trim: true) end)
|
||||
|> Enum.map(fn row -> String.split(row, "$", trim: true) end)
|
||||
maxfields = Enum.map(fieldsbyrow, fn field -> length(field) end) |> Enum.max
|
||||
colwidths = Enum.map(fieldsbyrow, fn field -> field ++ List.duplicate("", maxfields - length(field)) end)
|
||||
|> List.zip
|
||||
|
|
@ -15,9 +15,9 @@ defmodule Align do
|
|||
end)
|
||||
end
|
||||
|
||||
defp adjust(field, width, :Left), do: String.ljust(field, width)
|
||||
defp adjust(field, width, :Right), do: String.rjust(field, width)
|
||||
defp adjust(field, width, _), do: :string.centre(String.to_char_list(field), width)
|
||||
defp adjust(field, width, :Left), do: String.pad_trailing(field, width)
|
||||
defp adjust(field, width, :Right), do: String.pad_leading(field, width)
|
||||
defp adjust(field, width, _), do: :string.centre(String.to_charlist(field), width)
|
||||
end
|
||||
|
||||
text = """
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue