Skip to content

Instantly share code, notes, and snippets.

@sandeshsoni
Last active December 29, 2015 08:14
Show Gist options
  • Save sandeshsoni/ae62bb4b2e8824eb3bbf to your computer and use it in GitHub Desktop.
Save sandeshsoni/ae62bb4b2e8824eb3bbf to your computer and use it in GitHub Desktop.

Revisions

  1. Sandesh Soni renamed this gist Dec 28, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Sandesh Soni created this gist Dec 28, 2015.
    49 changes: 49 additions & 0 deletions ex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    defmodule Setup do
    def process vehicle do
    root_path = fn ->
    Car.folder_path vehicle
    end

    generate_labels root_path.(), vehicle
    create_sheets root_path.(), vehicle.sheets
    end

    def generate_labels directory_root, vehicle do
    File.mkdir_p Path.join(directory_root, "trims")
    sub_folder_path = fn(lab) ->
    directory_root
    |> Path.join("labels")
    |> Path.join(Atom.to_string(lab))
    |> Path.join(Map.get(vehicle,lab))
    end

    [
    :name,
    :brand,
    :region
    ]
    |> Enum.map( fn property -> sub_folder_path.(property) end)
    |> Enum.each( fn path -> File.mkdir_p!(path) end)
    end

    defp create_sheets(directory_root, sheets \\ []) do
    create_sheets_directory = fn() ->
    File.mkdir_p Path.join(directory_root, "Sheets")
    end

    process_sheet = fn
    x when is_bitstring(x) ->
    Specifico.download(x, directory_root)
    x when is_atom(x) ->
    Specifico.download(Atom.to_string(x),directory_root)
    { url, f_name } when is_tuple({ url, f_name }) ->
    Specifico.download(url, directory_root, f_name)
    x ->
    IO.puts x
    end

    create_sheets_directory.()
    sheets
    |> Enum.each(fn(sheet) -> process_sheet.(sheet) end)
    end
    end