Class: REXML::ReferenceWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/rexml/doctype.rb

Instance Method Summary collapse

Constructor Details

#initialize(id_type, public_id_literal, system_literal, context = nil) ⇒ ReferenceWriter

Returns a new instance of ReferenceWriter.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rexml/doctype.rb', line 11

def initialize(id_type,
               public_id_literal,
               system_literal,
               context=nil)
  @id_type = id_type
  @public_id_literal = public_id_literal
  @system_literal = system_literal
  if context and context[:prologue_quote] == :apostrophe
    @default_quote = "'"
  else
    @default_quote = "\""
  end
end

Instance Method Details

#write(output) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rexml/doctype.rb', line 25

def write(output)
  output << " #{@id_type}"
  if @public_id_literal
    if @public_id_literal.include?("'")
      quote = "\""
    else
      quote = @default_quote
    end
    output << " #{quote}#{@public_id_literal}#{quote}"
  end
  if @system_literal
    if @system_literal.include?("'")
      quote = "\""
    elsif @system_literal.include?("\"")
      quote = "'"
    else
      quote = @default_quote
    end
    output << " #{quote}#{@system_literal}#{quote}"
  end
end