Git Product home page Git Product logo

google-shopping-ruby's Introduction

Ruby Functions

Using the google shoping data used before (also included in this repository) create some useful functions to answer the following questions.

REMEMBER: data should be passed in to the function as arguments and out as a return value. DO NOT access/modify variables defined outside of the function.

Getting Started

  • Fork and clone this repository
  • install the byebug library: gem install byebug
  • Start creating functions in ruby/google_shopping_functions.rb
  • This starter code already gets and parses the JSON file for you.
  • write byebug on a line of your code to get a breakpoint

Deliverables

Create the following functions.

1.) getItems(objectData)

  • input: json object
  • returns: an array of items

Create a function called getItems that simply returns the items array from the google product object.

Note all other functions (below) use the return of this function as their input.

2.) getItemsByBrand(items, brand)

  • input: an array of items, a string of a brand to filter with
  • returns: an array of items (of a specific brand)

Create a function called getItemsByBrand that takes an item array returns a new array of all items of a specified brand.

Test this function by searching for Sony, Canon, Nikon and Panasonic.

3.) getItemsByAuthor(items, author)

  • input: an array of items, a string of an author to filter with
  • returns: an array of items (of a specific author)

Create a function called getItemsByAuthor that takes an item array and returns a new array of all items by a specified author.

Test this function by searching for Target, CDW, eBay

4.) getAvailableProducts(items)

  • input: an array of items
  • returns: an array of items (that are available)

Create function called getAvailableProducts that takes an item array and returns an array containing all of the available products (an available product is one with at least one availability of "inStock" in the inventories array)

5.) Use your functions

Use the functions you created in 1 - 4 to ouput (puts) the following lists of items.

  • All items made by Sony.
  • All items made by Sony that are available.
  • All available items by the author "Adorama Camera"
  • All items made by Nikon with the author eBay.

** Example Function Usage**

//verbose -- outputs all cannon products
items = getItems(data)
cannonItems = getItemsByBrand(items, 'Cannon')
puts cannonItems

//single line version -- does the same as above
puts getItemsByBrand(getItems(data), 'Cannon')

Further

After you have gotten your json hash, write some functions that uses these different enumerable methods, if you can.

all?
any?
each_with_index
find
find_all
find_index
map
reduce
reject
select
sort_by
take
uniq

Licensing

  1. All content is licensed under a CC-BY-NC-SA 4.0 license.
  2. All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact [email protected].

google-shopping-ruby's People

Contributors

awongh avatar bhague1281 avatar nickangtc avatar primaulia avatar raywtham avatar xnithunx avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.