Class: Sergio::ParsedDocument

Inherits:
Object
  • Object
show all
Includes:
HashMethods
Defined in:
lib/sergio/sergio_parsed_document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HashMethods

#hash_from_path, #hash_recursive_append, #hash_recursive_merge_to_arrays, #value_at_path

Constructor Details

#initializeParsedDocument

Returns a new instance of ParsedDocument.



6
7
8
# File 'lib/sergio/sergio_parsed_document.rb', line 6

def initialize
  @parsed_hash = {}
end

Instance Attribute Details

#parsed_hashObject

Returns the value of attribute parsed_hash.



4
5
6
# File 'lib/sergio/sergio_parsed_document.rb', line 4

def parsed_hash
  @parsed_hash
end

Instance Method Details

#set_element(path, val, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/sergio/sergio_parsed_document.rb', line 10

def set_element(path, val, options = {})
  old_val = value_at_path(path.clone, self.parsed_hash)

  if options[:as_array] && !val.is_a?(Array) && !old_val.is_a?(Array)
    val = [val]
  end

  h = hash_from_path(path, val)
  @parsed_hash = hash_recursive_append(self.parsed_hash, h)
  @parsed_hash
end