Class: StandardizeNumbers

Inherits:
Object
  • Object
show all
Defined in:
app/models/standardize_numbers.rb

Instance Method Summary collapse

Constructor Details

#initialize(record, attributes) ⇒ StandardizeNumbers

Returns a new instance of StandardizeNumbers.



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/standardize_numbers.rb', line 2

def initialize(record, attributes)
  @attributes = attributes

  if @attributes.kind_of?(Array)
    @attributes.each do |attribute|
      unless record[attribute].nil?
        value = record[attribute]

        if !(value =~ /\.\d+\,/).nil?
          value = value.gsub(/[.,]/, ',' => '.', '.' => '_')
        elsif !(value =~ /\,\d+\./).nil?
          value = value.gsub(/\,/, '_')
        elsif !(value =~ /\,/).nil?
          value = value.gsub(/\,/, '.')
        end

        record[attribute] = value
      end
    end
  end
end