Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
17 changes: 11 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# The directory Mix will write compiled artifacts to.
/_build
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover
/cover/

# The directory Mix downloads your dependencies sources to.
/deps
/deps/

# Where 3rd-party dependencies like ExDoc output generated docs.
/doc
# Where third-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch
Expand All @@ -19,6 +19,11 @@ erl_crash.dump
# Also ignore archive artifacts (built via "mix archive.build").
*.ez

.elixir_ls/
# Ignore package tarball (built via "mix hex.build").
nested_filter-*.tar

# Temporary files, for example, from tests.
/tmp/

# Misc.
.tool-versions
4 changes: 2 additions & 2 deletions LICENSE → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License
# MIT License

Copyright (c) [2017] [Bruce Park]
Copyright (c) 2017 Bruce Park

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# NestedFilter

![Build](https://github.com/treble37/nested_filter/actions/workflows/nested_filter_ci.yml/badge.svg?branch=master)
[![Maintainability](https://api.codeclimate.com/v1/badges/ba239c585908a0aad2ac/maintainability)](https://codeclimate.com/github/treble37/nested_filter/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/ba239c585908a0aad2ac/test_coverage)](https://codeclimate.com/github/treble37/nested_filter/test_coverage)
[![Coverage Status](https://coveralls.io/repos/github/treble37/nested_filter/badge.svg?branch=master)](https://coveralls.io/github/treble37/nested_filter?branch=master)
[![Hex.pm](https://img.shields.io/hexpm/v/nested_filter.svg)](https://hex.pm/packages/nested_filter)
[![Hex.pm Downloads](https://img.shields.io/hexpm/dt/nested_filter.svg)](https://hex.pm/packages/nested_filter)
[![GitHub stars](https://img.shields.io/github/stars/treble37/nested_filter.svg)](https://github.com/treble37/nested_filter/stargazers)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/treble37/nested_filter/master/LICENSE)
[![Module Version](https://img.shields.io/hexpm/v/nested_filter.svg)](https://hex.pm/packages/nested_filter)
[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/nested_filter/)
[![Total Download](https://img.shields.io/hexpm/dt/nested_filter.svg)](https://hex.pm/packages/nested_filter)
[![License](https://img.shields.io/hexpm/l/nested_filter.svg)](https://github.com/treble37/nested_filter/blob/master/LICENSE.md)
[![Last Updated](https://img.shields.io/github/last-commit/treble37/nested_filter.svg)](https://github.com/treble37/nested_filter/commits/master)

## The Problems

Expand Down Expand Up @@ -34,12 +34,14 @@ NestedFilter drills down into a nested map and can do any of the following:

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `nested_filter` to your list of dependencies in `mix.exs`:
The package can be installed by adding `:nested_filter` to your list of
dependencies in `mix.exs`:

```elixir
def deps do
[{:nested_filter, "~> 1.2.2"}]
[
{:nested_filter, "~> 1.2.2"}
]
end
```

Expand Down Expand Up @@ -89,3 +91,11 @@ assert NestedFilter.take_by_key(nested_map, [:b, :f]) == %{b: 1, f: 4 }
```

You can browse the tests for more usage examples.


## Copyright and License

Copyright (c) 2017 Bruce Park

This work is free. You can redistribute it and/or modify it under the
terms of the MIT License. See the [LICENSE.md](./LICENSE.md) file for more details.
6 changes: 3 additions & 3 deletions lib/nested_filter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule NestedFilter do

@doc """
Take a (nested) map and filter out any keys with specified values in the
values_to_reject list.
`values_to_reject` list.
"""
@spec drop_by_value(%{any => any}, [any]) :: %{any => any}
def drop_by_value(map, values_to_reject) when is_map(map) do
Expand All @@ -44,7 +44,7 @@ defmodule NestedFilter do

@doc """
Take a (nested) map and filter out any values with specified keys in the
keys_to_reject list.
`keys_to_reject` list.
"""
@spec drop_by_key(%{any => any}, [any]) :: %{any => any}
def drop_by_key(map, keys_to_reject) when is_map(map) do
Expand All @@ -68,7 +68,7 @@ defmodule NestedFilter do

@doc """
Take a (nested) map and keep any values with specified keys in the
keys_to_select list.
`keys_to_select` list.
"""
@spec take_by_key(%{any => any}, [any]) :: %{any => any}
def take_by_key(map, keys_to_select) when is_map(map) do
Expand Down
51 changes: 26 additions & 25 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,59 +1,60 @@
defmodule NestedFilter.Mixfile do
use Mix.Project

@source_url "https://github.com/treble37/nested_filter"
@version "1.2.2"

def project do
[
app: :nested_filter,
version: "1.2.2",
version: @version,
elixir: ">= 1.7.0",
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
test_coverage: [tool: ExCoveralls],
description: description(),
package: package(),
deps: deps()
deps: deps(),
docs: docs()
]
end

defp package do
[
description: "Drill down into a nested map and filter out keys "
<> "according to user specified values",
files: ["lib", "mix.exs", "README*", "LICENSE*"],
maintainers: ["Bruce Park"],
licenses: ["MIT"],
links: %{"GitHub" => "https://github.com/treble37/nested_filter"}
links: %{
"Changelog" => "https://hexdocs.pm/nested_filter/changelog.html",
"GitHub" => @source_url
}
]
end

defp description do
"""
Drill down into a nested map and filter out keys according to user
specified values
"""
end

# Configuration for the OTP application
#
# Type "mix help compile.app" for more information
def application do
# Specify extra applications you'll use from Erlang/Elixir
[extra_applications: [:logger]]
end

# Dependencies can be Hex packages:
#
# {:my_dep, "~> 0.3.0"}
#
# Or git/path repositories:
#
# {:my_dep, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
#
# Type "mix help deps" for more examples and options
defp deps do
[
{:ex_doc, ">= 0.25.3", only: :dev},
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false},
{:excoveralls, "~> 0.14.3", only: :test},
{:inch_ex, "~> 2.0.0", only: :docs},
{:credo, "~> 1.5.6", only: [:dev, :test]}
]
end

defp docs do
[
extras: [
"CHANGELOG.md": [],
"LICENSE.md": [title: "License"],
"README.md": [title: "Overview"]
],
main: "readme",
source_url: @source_url,
formatters: ["html"]
]
end
end