Class: TOML::Transformer

### Home Classes Methods

### In Files

- lib/toml/transformer.rb

### Parent

Parslet::Transform

### Methods

- ::parse_string
- ::visit_array

### Files

- LICENSE

### Class/Module Index

Quicksearch

- TOML
- TOML::Generator
- TOML::Key
- TOML::Parser
- TOML::Parslet
- TOML::Table
- TOML::TableArray
- TOML::Transformer
- Array
- DateTime
- FalseClass
- Hash
- Numeric
- Object
- String
- TrueClass

No matching classes.

# TOML::Transformer

### Public Class Methods

parse_string(val) click to toggle source

Utility to properly handle escape sequences in parsed string.

    # File lib/toml/transformer.rb, line 5
    def self.parse_string(val)
      e = val.length
      s = 0
      o = []
      while s < e
        if val[s].chr == "\\"
          s += 1
          case val[s].chr
          when "t"
            o << "\t"
          when "n"
            o << "\n"
          when "\\"
            o << "\\"
          when '"'
            o << '"'
          when "r"
            o << "\r"
          when "0"
            o << "\00""
          else
            raise "Unexpected escape character: '\\#{val[s]}'"
          end
        else
          o << val[s].chr
        end
        s += 1
      end
      o.join
    end

visit_array(h) click to toggle source

New array cleanup TODO: Make this more readable/understandable.

    # File lib/toml/transformer.rb, line 62
    def self.visit_array(h)
      if h.is_a? Hash
        # If it's an {:array => ...} hash
        a = h[:array]
        if a.is_a? Array
          # If the value is already an array
          a = a.map {|v| visit_array(v) }
          classes = a.map {|v|
            # Grab the class, with a little exception for true and false since
            # they're different classes (TrueClass and FalseClass).
            (v == true || v == false) ? true : v.class
          }
          if classes.uniq.length != 1
            raise "Conflicting types in array: " +                classes.map(&:to_s).join(", ")
          end
          return a
        else
          # Turn the value into an array
          return [visit_array(a)].compact
        end
      else
        # Plain old non-hash value
        return h
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.