Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds: Brand filtering #9

Merged
merged 4 commits into from
Jul 17, 2018
Merged

Adds: Brand filtering #9

merged 4 commits into from
Jul 17, 2018

Conversation

willdavidow
Copy link
Contributor

@willdavidow willdavidow commented Jul 12, 2018

Adds ability to filter brands by configuration object. Configuration object is flexible, model is as follows:

{
  [brand_name]: {
     [filter_key]: [
         'value 1',
         'value 2',
         ...
     ],
     [filter_key]: [
        'value 1',
        'value 2'
     ]
  },
  [brand_name]: { 
      ... etc...
  }
}

the filterBrands(brands, filters, returnFilteredFields = false) function accepts three parameters:

  1. Abrands object (e.g. libmoji.getBrands('male'))
  2. A filter configuration object (examples below)
  3. A boolean flag to include (true) or exclude (false, this is default) items that are in the filter
    configuration.
    Example usage:

Exclude items from config object in brand-specific filtered result set:

const filteredBrands = libmoji.filterBrands(
  libmoji.getBrands('male'), 
  {
      // filtering by the mlb brand name
      MLB: {
        // matching against each outfit's `id` key
        id: [
           // filter out these items
          1018190 // Boston Red Sox
        ]
      },
      // filtering by the nfl brand name
      NFL: {
        // matching against each outfit's `id` key
        id: [
           // filter out these items
          1018373 // NE Patriots
        ]
      },
      NHL: {
        // matching against each outfit's  `description` key
        description: [ 
           // filter out these teams, 
          'Boston Bruins',
          'New Jersey Devils',
          'New York Islanders',
          'Pittsburgh Penguins',
          'Philadelphia Flyers',
          'Washington Capitals'
        ]
      }
  }
 //, false // exclude items listed in config (no need to explicitly pass `false` since it's the default setting)
);

Include ONLY items from config object in brand-specific filtered result set by passing the third parameter as true (it defaults to false). Brands that have no filtering configuration will pass through and return their complete set.

const filteredBrands = libmoji.filterBrands(
  libmoji.getBrands('male'), 
  {
      MLB: {
        // matching against each outfit's  `id` key
        id: [
           // include only these items
          1018194, // Houston Astros
          1018198, // NY Yankees
          1018212 // NY Mets
        ]
      },
      NFL: {
        // matching against each outfit's  `id` key
        id: [
           // include only these items
          1018356 // NY Giants
        ]
      },
      // filtering by the nhl brand name
      NHL: {
        // matching against each outfit's  `description` key
        description: [ 
           // include only these items
          'New York Rangers',
        ]
      }
  }, 
  true // return items listed in each config, excluding all others for that brand
);

- Provides ability to filter brands by way of a configuration object, e.g. { NHL: { description: ['Anaheim Ducks', 'Dallas Stars'] } will filter the ducks and dallas stars out of NHL outfit results (using the description key as the matching field).
@willdavidow
Copy link
Contributor Author

willdavidow commented Jul 12, 2018

I can definitely add documentation around how one might use this since it requires a bit of digging into and learning a bit about the actual data.

edit: modified the example(s) above - hopefully those can suffice for documentation around how one would filter things in/out, as well as the important bits of outfit data coming out of https://api.bitmoji.com/content/templates

@matthewnau matthewnau self-requested a review July 16, 2018 16:16
@matthewnau matthewnau self-assigned this Jul 16, 2018
@matthewnau matthewnau added the enhancement New feature or request label Jul 16, 2018
@matthewnau
Copy link
Owner

@willdavidow should this be its own wiki page or added into the traditional docs that I provided? If its the latter, would you be able to update the formatting so it matches the style of documentation that I originally provided?

@matthewnau matthewnau merged commit 7da848d into matthewnau:master Jul 17, 2018
@willdavidow
Copy link
Contributor Author

willdavidow commented Jul 17, 2018

I'd imagine it makes sense for it to be included in traditional documentation since it's part of the library API..

I'll update the docs a little later on today so they match the formatting of the Libmoji Docs Wiki you've already defined.

@willdavidow
Copy link
Contributor Author

willdavidow commented Jul 17, 2018

@matthewnau, how's this:

filterBrands(brands, filters, returnFilteredFields = false)

Takes a brands object, a filters object and returnFilteredFields boolean (false => exclude items from filters; true => return only items from filters). Full brand is returned if no matching key exists in filters.
Returns a filtered brands object.

Exclude filters example:

const filteredBrands = libmoji.filterBrands(
  libmoji.getBrands('male'), 
  {
      // filtering by the mlb brand name
      MLB: {
        // matching against each outfit's `id` key
        id: [
           // filter out this item
          1018190 // Boston Red Sox
        ]
      },
      // filtering by the nfl brand name
      NFL: {
        // matching against each outfit's `id` key
        id: [
           // filter out this item
          1018373 // NE Patriots
        ]
      },
      NHL: {
        // matching against each outfit's  `description` key
        description: [ 
           // filter out these teams, 
          'Boston Bruins',
          'New Jersey Devils',
          'New York Islanders',
          'Pittsburgh Penguins',
          'Philadelphia Flyers',
          'Washington Capitals'
        ]
      }
  }
 //, false // exclude items listed in config (no need to explicitly pass `false` since it's the default setting)
);

console.log('filtered brands: ', filteredBrands);
/* console would print list of filtered brands with specific items from the config object removed from the MLB, NFL and NHL brands; all other brands returned untouched */

Include filters example:

const filteredBrands = libmoji.filterBrands(
  libmoji.getBrands('male'), 
  {
      MLB: {
        // matching against each outfit's  `id` key
        id: [
           // include only these items
          1018194, // Houston Astros
          1018198, // NY Yankees
          1018212 // NY Mets
        ]
      },
      NFL: {
        // matching against each outfit's  `id` key
        id: [
           // include only this item
          1018356 // NY Giants
        ]
      },
      // filtering by the nhl brand name
      NHL: {
        // matching against each outfit's  `description` key
        description: [ 
           // include only this item
          'New York Rangers'
        ]
      }
  }, 
  true // return items listed in each config, excluding all others for that brand
);

console.log('filtered brands: ', filteredBrands);
/* console would print list of filtered brands. The MLB, NFL and NHL brands would include only the items listed in the config object; all other brands returned untouched */

@matthewnau
Copy link
Owner

@willdavidow yes this is good. I'll upload when I can. Thanks! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants