XmlMini
要使用更快的 libxml 解析器
gem "libxml-ruby"
XmlMini.backend = 'LibXML'
方法
- B
- R
- T
- W
常量
DEFAULT_ENCODINGS | = | { "binary" => "base64" } unless defined?(DEFAULT_ENCODINGS) |
FORMATTING | = | { "symbol" => Proc.new { |symbol| symbol.to_s }, "date" => Proc.new { |date| date.to_fs(:db) }, "dateTime" => Proc.new { |time| time.xmlschema }, "duration" => Proc.new { |duration| duration.iso8601 }, "binary" => Proc.new { |binary| ::Base64.encode64(binary) }, "yaml" => Proc.new { |yaml| yaml.to_yaml } } unless defined?(FORMATTING) |
PARSING | = | { "symbol" => Proc.new { |symbol| symbol.to_s.to_sym }, "date" => Proc.new { |date| ::Date.parse(date) }, "datetime" => Proc.new { |time| Time.xmlschema(time).utc rescue ::DateTime.parse(time).utc }, "duration" => Proc.new { |duration| Duration.parse(duration) }, "integer" => Proc.new { |integer| integer.to_i }, "float" => Proc.new { |float| float.to_f }, "decimal" => Proc.new do |number| if String === number number.to_d else BigDecimal(number) end end, "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.to_s.strip) }, "string" => Proc.new { |string| string.to_s }, "yaml" => Proc.new { |yaml| YAML.load(yaml) rescue yaml }, "base64Binary" => Proc.new { |bin| ::Base64.decode64(bin) }, "hexBinary" => Proc.new { |bin| _parse_hex_binary(bin) }, "binary" => Proc.new { |bin, entity| _parse_binary(bin, entity) }, "file" => Proc.new { |file, entity| _parse_file(file, entity) } } |
TYPE_NAMES | = | { "Symbol" => "symbol", "Integer" => "integer", "BigDecimal" => "decimal", "Float" => "float", "TrueClass" => "boolean", "FalseClass" => "boolean", "Date" => "date", "DateTime" => "dateTime", "Time" => "dateTime", "ActiveSupport::Duration" => "duration", "Array" => "array", "Hash" => "hash" } |
属性
[RW] | 深度 |
实例公共方法
backend() 链接
backend=(name) 链接
rename_key(key, options = {}) 链接
# File activesupport/lib/active_support/xml_mini.rb, line 152 def rename_key(key, options = {}) camelize = options[:camelize] dasherize = !options.has_key?(:dasherize) || options[:dasherize] if camelize key = true == camelize ? key.camelize : key.camelize(camelize) end key = _dasherize(key) if dasherize key end
to_tag(key, value, options) 链接
# File activesupport/lib/active_support/xml_mini.rb, line 119 def to_tag(key, value, options) type_name = options.delete(:type) merged_options = options.merge(root: key, skip_instruct: true) if value.is_a?(::Method) || value.is_a?(::Proc) if value.arity == 1 value.call(merged_options) else value.call(merged_options, key.to_s.singularize) end elsif value.respond_to?(:to_xml) value.to_xml(merged_options) else type_name ||= TYPE_NAMES[value.class.name] type_name ||= value.class.name if value && !value.respond_to?(:to_str) type_name = type_name.to_s if type_name type_name = "dateTime" if type_name == "datetime" key = rename_key(key.to_s, options) attributes = options[:skip_types] || type_name.nil? ? {} : { type: type_name } attributes[:nil] = true if value.nil? encoding = options[:encoding] || DEFAULT_ENCODINGS[type_name] attributes[:encoding] = encoding if encoding formatted_value = FORMATTING[type_name] && !value.nil? ? FORMATTING[type_name].call(value) : value options[:builder].tag!(key, formatted_value, attributes) end end