Class: PerfectTOML::Generator

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

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj, out, sort_keys: false, use_literal_string: false, use_multiline_string: false, use_dot: false) ⇒ Generator

Returns a new instance of Generator.



758
759
760
761
762
763
764
765
766
767
# File 'lib/perfect_toml.rb', line 758

def initialize(obj, out, sort_keys: false, use_literal_string: false, use_multiline_string: false, use_dot: false)
  @obj = obj.to_hash
  @out = out
  @first_output = true

  @sort_keys = sort_keys
  @use_literal_string = use_literal_string
  @use_multiline_string = use_multiline_string
  @use_dot = use_dot
end

Class Method Details

.escape_basic_string(str) ⇒ Object



778
779
780
781
782
783
784
# File 'lib/perfect_toml.rb', line 778

def self.escape_basic_string(str)
  str = str.gsub(/["\\\x00-\x08\x0a-\x1f\x7f]/) do
    c = ESCAPE_CHARS[$&]
    c ? "\\" + c : "\\u%04x" % $&.ord
  end
  "\"#{ str }\""
end

.escape_key(key) ⇒ Object



774
775
776
# File 'lib/perfect_toml.rb', line 774

def self.escape_key(key)
  new({}, "").send(:escape_key, key)
end

Instance Method Details

#generateObject



769
770
771
772
# File 'lib/perfect_toml.rb', line 769

def generate
  generate_hash(@obj, "", false)
  @out
end