Sha256: e1fb2709fe1a1ca5bf9320f6f15765c2006a0bf1ef9536f9505099dc11d4854b

Contents?: true

Size: 1.04 KB

Versions: 20

Compression:

Stored size: 1.04 KB

Contents

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

class SearchCardContext < Cardio::Migration::Core
  def up
    sep = /\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
      %w[left LL],
      %w[right LR],
      %w[self left],
      ["",       "left"]
    ]
    Card.search(type_id: ["in", Card::SearchTypeID, Card::SetID]).each do |card|
      next unless card.name.compound? && card.real?

      content = card.db_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|
        next unless (content_change = action.change :db_content)
        next if content_change.new_record?

        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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
card-1.105.6 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.105.5 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.105.4 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.105.3 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.105.2.pre1 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.105.2 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.105.1 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.105.0 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.104.2 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.104.1 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.104.0 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.103.4 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.103.3 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.103.2 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.103.1 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.103.0 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.101.7 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.102.0 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.101.6 db/migrate_core_cards/20150429090551_search_card_context.rb
card-1.101.5 db/migrate_core_cards/20150429090551_search_card_context.rb