Class: Mysql::Result

Inherits:
Object show all
Defined in:
lib/joffice/mysql_utf8.rb

Instance Method Summary collapse

Instance Method Details

#each_hash_utf8(&block) ⇒ Object Also known as: each_hash



33
34
35
36
37
38
# File 'lib/joffice/mysql_utf8.rb', line 33

def each_hash_utf8(&block)
  each_hash_orig do |row|
    row.each {|k, v| row[k] = encode(v) }
    yield(row)
  end
end

#each_utf8(&block) ⇒ Object Also known as: each



25
26
27
28
29
# File 'lib/joffice/mysql_utf8.rb', line 25

def each_utf8(&block)
  each_orig do |row|
    yield row.map {|col| encode(col) }
  end
end

#encode(value, encoding = "utf-8") ⇒ Object



21
22
23
# File 'lib/joffice/mysql_utf8.rb', line 21

def encode(value, encoding = "utf-8")
  String === value ? value.force_encoding(encoding) : value
end