Class: Storyblok::Links

Inherits:
Object
  • Object
show all
Defined in:
lib/storyblok/links.rb

Instance Method Summary collapse

Constructor Details

#initialize(response_obj) ⇒ Links

Returns a new instance of Links.



3
4
5
# File 'lib/storyblok/links.rb', line 3

def initialize(response_obj)
  @links = response_obj["data"]["links"]
end

Instance Method Details

#as_treeObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/storyblok/links.rb', line 7

def as_tree
  tree = {}

  @links.each do |key, item|
    if tree[item["parent_id"]].nil?
      tree[item["parent_id"]] = []
    end

    tree[item["parent_id"]] << item
  end

  generate_tree(0, tree)
end