class Scrawl

Constants

DEFAULT_SPLAT_CHARACTER
KEY_VALUE_DELIMITER
NAMESPACE_DELIMITER
PAIR_DELIMITER
VERSION

Public Class Methods

new(*trees) click to toggle source
# File lib/scrawl.rb, line 9
def initialize(*trees)
  @tree = trees.inject({}) { |global, tree| global.merge(tree) }
end

Public Instance Methods

each(&block) click to toggle source
# File lib/scrawl.rb, line 33
def each(&block)
  tree.each(&block)
end
inspect(namespace = nil) click to toggle source
# File lib/scrawl.rb, line 17
def inspect(namespace = nil)
  tree.map do |key, value|
    case
      when value.nil? then nil
      when value.respond_to?(:none?) && value.none? then nil
      when value.respond_to?(:push) then itemize(namespace, key, value)
      when value.respond_to?(:merge) then Scrawl.new(value).inspect(key)
      else label(namespace, key) + KEY_VALUE_DELIMITER + element(value)
    end
  end.flatten.compact.join(PAIR_DELIMITER)
end
merge(hash) click to toggle source
# File lib/scrawl.rb, line 13
def merge(hash)
  @tree.merge!(hash.to_hash)
end
to_h() click to toggle source
# File lib/scrawl.rb, line 41
def to_h
  tree.to_h
end
to_hash() click to toggle source
# File lib/scrawl.rb, line 37
def to_hash
  tree.to_hash
end
to_s(namespace = nil) click to toggle source
# File lib/scrawl.rb, line 29
def to_s(namespace = nil)
  inspect(namespace)
end

Private Instance Methods

element(value) click to toggle source
# File lib/scrawl.rb, line 49
        def element(value)
  case value
    when Proc then element(value.call)
    when Symbol then element(value.to_s)
    else value.inspect
  end
end
itemize(namespace, key, list) click to toggle source
# File lib/scrawl.rb, line 61
        def itemize(namespace, key, list)
  list.map do |item|
    label(namespace, label(key, DEFAULT_SPLAT_CHARACTER)) + KEY_VALUE_DELIMITER + element(item)
  end
end
label(namespace, key) click to toggle source
# File lib/scrawl.rb, line 45
        def label(namespace, key)
  [namespace, key].compact.join(NAMESPACE_DELIMITER)
end
tree() click to toggle source
# File lib/scrawl.rb, line 57
        def tree
  @tree
end