module ICU::Util::File
Public Class Methods
load_ini(name)
click to toggle source
Load an INI file and convert to a hash.
# File lib/icu_tournament/util.rb, line 38 def self.load_ini(name) text = self.read_utf8(name) data = Hash.new header = nil text.split(/\n/).each do |line| if line.match(/^\s*\[([^\]]+)\]\s*$/) header = $1.strip header = nil if header == "" elsif header && line.match(/^([^=]+)=(.*)$/) key = $1.strip val = $2.strip unless key == "" data[header] ||= Hash.new data[header][key] = val end end end data end
read_utf8(name)
click to toggle source
Read UTF data from a file.
# File lib/icu_tournament/util.rb, line 28 def self.read_utf8(name) ::File.open(name, "r:ASCII-8BIT") do |f| data = f.read bom = "\xEF\xBB\xBF".force_encoding("ASCII-8BIT") data.sub!(/^#{bom}/, "") # get rid of a UTF-8 BOM ICU::Util::String.to_utf8(data) # defined in icu_name end end