Sha256: 97fe3206bd53247e42d32786cb56e8b2876841dd522d53535bd6d772b289b4d0

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

Feature: Transforming the record

  The `transform` block is passed the current record of the file that is being read. This record is a Hash with
  its keys defined in the corresponding `file` definition and its values read from the input file. The record
  can be transformed arbitrarily with pure Ruby code. The `output` command will write the record to file
  using only the keys that are defined in the `file` definition of the transformation's target file.


  Scenario: Using the record as a Hash
    Given a file named "command_script.rb" with:
    """
    file :products do
      field :id
      field :name
      field :main_category
      field :subcategory
    end

    file :transformed_products do
      field :item
      field :title
      field :category
    end

    transform :products, into: :transformed_products do |record|
      record[:item] = record[:id]
      record[:title] = record[:name].upcase
      record[:category] = [record[:main_category], record[:subcategory]].join " > "
      output record
    end
    """
    And a file named "products.csv" with:
    """
    id,name,main_category,subcategory
    IE-123,first product,Main category,Subcategory
    TM-234,second product,Group,Subgroup
    """
    When I run `forge command_script.rb`
    Then the exit status should be 0
    And a file named "transformed_products.csv" should exist
    And the file "transformed_products.csv" should contain exactly:
    """
    item,title,category
    IE-123,FIRST PRODUCT,Main category > Subcategory
    TM-234,SECOND PRODUCT,Group > Subgroup

    """

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
data_forge-0.1.1 features/transform/record_transformation.feature
data_forge-0.1 features/transform/record_transformation.feature