Giter Club home page Giter Club logo

parser's Introduction

Parser

Test project items parser.

You must have installed and runned PostgreSQL and Redis servers. Redis server needed for gem sidekiq.

Before run this project you should run followed instructions from the project folder:

bundle install
rake db:create
rake db:migrate

For run this project you should run followed instructions from the project folder:

rails server
bundle exec sidekiq

That will run server on port 3000. Main project page is {your_ip}:3000.

Project has very simple interface. For creating new partner click on "New partner" link. Also you can show, edit and remove each partner by links near each row of the partners table.

After creating or updating partner, server runs background process for parsing file by gem sidekiq.

For creating new formats you should create new file in app/workers directory. Then in this file describe new class {YourClassName}Worker and inherit it from AbstractWorker class. This class must override methods "document" and "items". Method "document" has StringIO io variable and must return parsed doc. Method "items" has your parsed doc variable and must return array of hashes with fields:

  • :title
  • :partner_item_id
  • :available_in_store

Example of new format class for xml.

class XmlWorker < AbstractWorker

  def document(io)
    Nokogiri::XML io
  end

  def items(doc)
    doc.css('item').map do |item|
      {
        title: item.css('title').text,
        partner_item_id: item.attr('id'),
        available_in_store: item.attr('available')
      }
    end
  end
end

Example of new format class for json.

class JsonWorker < AbstractWorker

  def document(io)
    JSON.load io
  end

  def items(doc)
    doc['items'].map do |item|
      {
        title: item['title'],
        partner_item_id: item['id'],
        available_in_store: item['available']
      }
    end
  end
end

After that you can use {YourClassName} as xml_type when creating and updating partner.

Results of parsed items you can see on show page of each partner or in PostgreSQL database in table "items".

parser's People

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.