Coder Social home page Coder Social logo

knowncitizen / schlepp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from timting/schlepp

0.0 1.0 0.0 119 KB

Schlepp is a gem for normalizing and importing data from various formats. It can currently normalize CSV data and pull from RDBMS sources by using ActiveRecord transparently. Schlepp is based on a simple DSL.

schlepp's Introduction

Schlepp

Description

Schlepp makes it easy to normalize data from various sources like CSV. Need to go from flattened CSV to relational tables? Schlepp provides a simple DSL for mapping, grouping and importing data from and to various formats.

At least that’s the plan. Currently handles access to CSV files.

Usage

Schlepp::Burden.new :products do
  cd 'data/'

  glob 'catalogs/*' do |dir|
    file 'Csv' do |csv|
      csv.name = 'products.csv'
      csv.load_mapping 'config/products.yml'
      csv.groups = [3, 4]

      csv.map do |product|
        product_record = Product.create(:name => product[:name])
        product.children.each do |color|
          color_record = Color.create(:name => color[:name])
          product_record.colors << color_record
          color.children.each do |size|
            size_record = Size.create(:name => size[:name])
            color.sizes << size_record
          end
        end
      end

    end
  end

  # Schlepp::Db uses ActiveRecord internally, so AR style configuration and
  # manipulation.
  db do |database|
    database.config = {
      adapter:  'mysql',
      host:     'localhost',
      username: 'root',
      password: 'root',
      database: 'test_db'
    }

    database.table :posts do |posts|
      posts.default_scope do
        where(:is_deleted => false)
      end

      # association options are passed to the corresponding AR method
      posts.has_many :comments, :class_name => 'CoolComments' do |comments|
        comments.default_scope do
          limit(2)
        end
      end

      posts.each do |post|
        # post is now an instance of a model descended from ActiveRecord::Base
        # meaning post.comments works fine, or any other AR stuff.
        # you would do something with the post here.
      end
    end

  end

end

schlepp's People

Contributors

timting 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.