Sha256: 31b31041d98cd499b2827292681ad6f0128dc0ec23cdc3c25d3fbd7f586cb35a

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

# -*- encoding : utf-8 -*-

class SearchCardContext < Card::CoreMigration
  def up
    sep = %r{\W}
    replace = [
      ['[lr]+','l\\1'],
      ['[LR]+','L\\1'],
      ['(?=[LR]*[lr]+)(?=[lr]*[LR]+)[lrLR]+','l\\1'],   # mix of lowercase and uppercase l's and r's
      ['left',   'LL'],
      ['right',  'LR'],
      ['self',   'left'],
      ['',       'left'],
    ]
    Card.search(type_id: ['in', Card::SearchTypeID, Card::SetID]).each do |card|
      if card.cardname.junction? && !card.virtual?
        content = card.content
        replace.each do |key, val|
          content.gsub!(/(#{sep})_(#{key})(?=#{sep})/, "\\1_#{val}")
        end
        card.update_column :db_content, content
        card.actions.each do |action|
          if (content_change = action.change_for(:db_content).first)
            content = content_change.value
            replace.each do |key, val|
              content.gsub!(/(#{sep})_(#{key})(?=#{sep})/, "\\1_#{val}")
            end
            content_change.update_column :value, content
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
card-1.16.8 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.16.7 db/migrate_core_cards/20150429090551_search_card_context.rb