class Ecoportal::API::V2::Page

Constants

ALLOWED_KEYS

Public Class Methods

new(doc = [], parent: self, key: nil) click to toggle source
# File lib/ecoportal/api/v2/page.rb, line 32
def initialize(doc = [], parent: self, key: nil)
  super(_doc_bug_fix(doc), parent: parent, key: key)
end

Public Instance Methods

as_update() click to toggle source
# File lib/ecoportal/api/v2/page.rb, line 36
def as_update
  super.tap do |hash|
    unless !hash
      hash["data"].select! do |key, value|
        ALLOWED_KEYS.include?(key)
      end
      return nil if (hash["data"].keys - ["patch_ver"]).empty?
    end
  end
end
stages?() click to toggle source
# File lib/ecoportal/api/v2/page.rb, line 47
def stages?
  self.stages.count > 0
end

Private Instance Methods

_doc_bug_fix(hash) click to toggle source
# File lib/ecoportal/api/v2/page.rb, line 53
def _doc_bug_fix(hash)
  hash.tap do |hash|
    _fix_doc(hash["stages"], "flow_node_ids", "section_ids") if hash.key?("stages")
    if hash.key?("sections")
      _fix_doc(hash["sections"], "membrane_ids", "component_ids")
      _fix_doc(hash["sections"], "left_membrane_ids", "left_component_ids")
      _fix_doc(hash["sections"], "right_membrane_ids", "right_component_ids")
    end
  end
end
_fix_doc(value, source, dest) click to toggle source
# File lib/ecoportal/api/v2/page.rb, line 64
def _fix_doc(value, source, dest)
  value.tap do |value|
    case value
    when Array
      value.each {|v| _fix_doc(v, source, dest)}
    when Hash
      if value.key?(source) && !value.key?(dest)
        value[dest] = value[source]
        value.delete(source)
      end
    else
      # Do nothing!
    end
  end
end