15 Replies Latest reply: Feb 10, 2014 8:54 AM by neetha P RSS

    Load data from ruby file

    neetha P

      Hi All,

       

      Please any can help me how to get data from ruby file

        • Re: Load data from ruby file
          Srikanth P

          What type of files these are ?

           

          Try with fixed delimited format

            • Re: Load data from ruby file
              neetha P

              Hi Dathu,

               

              Please see below code:

               

              require 'rubygems'
              require 'mysql'
              require "rspec"
              require 'rspec/expectations'
              require 'active_support/deprecation'
              require 'active_support/dependencies'
              #ActiveSupport::Dependencies.autoload_paths << File.expand_path(File.join(Dir.pwd, 'lib'))

              def r_for_retailer(retailer)
              retailer = retailer.downcase
                case retailer
                when "Targetus"
                  $r1="Target-US--List"
                  $r2="Target-US--Detail"
                  $product_count = 3842
                  $brand_count = 1
                  $swatch_images = true
                  $product_images = true
                  $product_description = true
                  $product_details = true
                  $colour_tags = true
                  $menu2_tags = false
                  $currency = "USD"
                  $country = "US"
                  $retailer_name = "Target-us"
                when "Relianceus"
                  $r1="Reliance-US--List"
                  $r2="Reliance-US--Detail"
                  $product_count = 5000
                  $brand_count = 1
                  $swatch_images = true
                  $product_images = true
                  $product_description = true
                  $product_details = true
                  $colour_tags = true
                  $menu2_tags = false
                  $currency = "USD"
                  $country = "US"
                  $retailer_name = "Reliance-us"
                when "little"
                  $r1="Little-List"
                  $r2="Little-UK--Detail"
                  $product_count = 7966
                  $brand_count = 249
                  $swatch_images = true
                  $product_images = true
                  $product_description = true
                  $product_details = true
                  $colour_tags = true
                  $menu2_tags = false
                  $currency = "GBP"
                  $country = "UK"
                  $retailer_name = "little-uk"
                when "Hollandus"
                  $r1="Holland-US--List"
                  $r2="Holland-US--Detail"
                  $product_count = 10248
                  $brand_count = 464
                  $swatch_images = true
                  $product_images = true
                  $product_description = true
                  $product_details = true
                  $colour_tags = true
                  $menu2_tags = false
                  $currency = "USD"
                  $country = "US"
                  $retailer_name = "Holland-us"
               
                end

              end

              AfterStep do
                if !$retailer.eql?$old_retailer
                  connect_to_database
                  #   create_schema
                  robots_for_retailer($retailer)
                  #  copy_data_in_database
                end
                $old_retailer = $retailer
              end

              at_exit do
              #  write_statistics
                $db.close
              end
              end

               

               

              When tried to load data its its only support fixed record option.

               

              Status.PNG

            • Re: Load data from ruby file
              Peter Cammaert

              This is a weird discussion. Here's the result of my guesswork.

               

              QlikView is a capable ETL tool that easily reads data in various formats and databases. Some manual work is still necessary however when attempting to read novels, tax forms, license plates and source code. Your example contains only four groups of setting so I took the time to manually convert them into something QlikView can understand. See attachments.

               

              If in reality there are many more groups in the ruby source, you may consider writing a tool in a general purpose scripting language (like perl) to process groups of values into comma-separated lines.

               

               

              Note that the ruby code is a little bit inconsistent. The last value is stored in a variable alternately called r_name or retailer_name.

               

              Good luck,

               

              Peter

                • Re: Load data from ruby file
                  neetha P

                  hi Peter,

                   

                  Thanks for help and Its a typo mistake,retailer_name is correct.

                  i don't have idea how ruby file is converted to csv or excel.

                  its a regular update we need from ruby file.

                   

                  Thanks

                  Nitha

                    • Re: Load data from ruby file
                      Peter Cammaert

                      Well, the attachment is only an example of what to feed into QlikView.

                       

                      If you need updates on a regular basis, that means that someone or something is updating the ruby code on a regular basis as well. These updates can be done anywhere (csv, ruby program, database table) as long as you don't have to do them twice and in different places. As far as I can see with limited information, you have two options to handle this quickly:

                      • Change your ruby code so that the configuration information is read from an external (csv?) file. The updates need only be done in a single spot, the external file, and both the ruby program and your QlikView application will follow suit. Your r_for_retailer subroutine now needs to do a csv table load, a lookup with the value of parameter retailer, and a load of the different variables with the values found in the corresponding columns.
                      • Or recode the ruby program so that the settings for every retailer value are listed in a table-like format at the beginning of the program (a dictionary or whatever this is called in ruby). If you tag the table with comment-like items before and after the actual rows, QlikView can be programmed to extract these lines without too much difficulty.

                       

                      But keep in mind that the QlikView script engine is no parser construction toolkit.

                       

                      Peter

                  • Re: Load data from ruby file
                    neetha P

                    Hi All,

                     

                    Please check rb file i attached and help me with solution