Module: OM

Defined in:
lib/om.rb,
lib/om/xml/dynamic_node.rb

Defined Under Namespace

Modules: Samples, TreeNode, XML

Class Method Summary collapse

Class Method Details

.destringify(params) ⇒ Object

Recursively changes any strings beginning with : to symbols and any number strings to integers Converts [“:person”=>“0”, “:last_name”] to [:person=>0, :last_name]



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/om.rb', line 9

def self.destringify(params)
  case params
  when String       
    if params == "0" || params.to_i != 0
      result = params.to_i
    elsif params[0,1] == ":"
      result = params.sub(":","").to_sym
    else
      result = params.to_sym
    end
    return result
  when Hash 
    result = {}
    params.each_pair do |k,v|
      result[ destringify(k) ] = destringify(v)
    end
    return result
  when Array 
    result = []
    params.each do |x|
      result << destringify(x)
    end
    return result
  else
    return params
  end
end

.pointers_to_flat_array(pointers, include_indices = true) ⇒ Object

Convert a Term pointer into a flat array without Hashes. If include_indices is set to false, node indices will be removed.

Examples:

Turn a pointer into a flat array with node indices preserved

OM.pointers_to_flat_array( [{:conference=>0}, {:role=>1}, :text] ) 
=> [:conference, 0, :role, 1, :text]

Remove node indices by setting include_indices to false

OM.pointers_to_flat_array( [{:conference=>0}, {:role=>1}, :text], false ) 
=> [:conference, :role, :text]

Parameters:

  • pointers (Array)

    array that you would pass into other Accessor methods

  • include_indices (Boolean) (defaults to: true)

    (default: true) if set to false, parent indices will be excluded from the array



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/om.rb', line 48

def self.pointers_to_flat_array(pointers, include_indices=true)
  flat_array = []
  pointers.each do |pointer|
    if pointer.kind_of?(Hash)
      flat_array << pointer.keys.first
      if include_indices 
        flat_array << pointer.values.first
      end
    else
      flat_array << pointer
    end
  end
  return flat_array
end

.versionObject



63
64
65
# File 'lib/om.rb', line 63

def self.version
  Om::VERSION
end