Class: VRT::Map

Inherits:
Object
  • Object
show all
Defined in:
lib/vrt/map.rb

Constant Summary collapse

DEPTH_MAP =
{
  'category' => 1,
  'subcategory' => 2,
  'variant' => 3
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version = nil) ⇒ Map

Returns a new instance of Map.



11
12
13
14
15
16
17
18
# File 'lib/vrt/map.rb', line 11

def initialize(version = nil)
  @version = version || VRT.current_version
  @structure = build_structure
  @_found_nodes = {}
  @_lineages = {}
  @_valid_vrt_ids = {}
  @_valid_identifiers = {}
end

Instance Attribute Details

#structureObject (readonly)

Returns the value of attribute structure.



9
10
11
# File 'lib/vrt/map.rb', line 9

def structure
  @structure
end

#versionObject (readonly)

Returns the value of attribute version.



9
10
11
# File 'lib/vrt/map.rb', line 9

def version
  @version
end

Instance Method Details

#categoriesObject

Returns list of top level categories in the shape:

{ value: category_id, label: category_name }


34
35
36
37
38
39
# File 'lib/vrt/map.rb', line 34

def categories
  structure.keys.map do |key|
    node = find_node(key.to_s, max_depth: 'category')
    { value: node.id, label: node.name }
  end
end

#find_node(string, max_depth: 'variant') ⇒ Object



20
21
22
# File 'lib/vrt/map.rb', line 20

def find_node(string, max_depth: 'variant')
  @_found_nodes[string + max_depth] ||= walk_node_tree(string, max_depth: max_depth)
end

#get_lineage(string, max_depth: 'variant') ⇒ Object



28
29
30
# File 'lib/vrt/map.rb', line 28

def get_lineage(string, max_depth: 'variant')
  @_lineages[string + max_depth] ||= construct_lineage(string, max_depth)
end

#valid?(vrt_id) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/vrt/map.rb', line 24

def valid?(vrt_id)
  @_valid_vrt_ids[vrt_id] ||= valid_identifier?(vrt_id) && !find_node(vrt_id).nil?
end