Class: VRT::Map
- Inherits:
-
Object
- Object
- VRT::Map
- Defined in:
- lib/vrt/map.rb
Constant Summary collapse
- DEPTH_MAP =
{ 'category' => 1, 'subcategory' => 2, 'variant' => 3 }.freeze
Instance Attribute Summary collapse
-
#structure ⇒ Object
readonly
Returns the value of attribute structure.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#categories ⇒ Object
Returns list of top level categories in the shape: [{ value: category_id, label: category_name }].
- #find_node(string, max_depth: 'variant') ⇒ Object
- #get_lineage(string, max_depth: 'variant') ⇒ Object
-
#initialize(version = nil) ⇒ Map
constructor
A new instance of Map.
- #valid?(vrt_id) ⇒ Boolean
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
#structure ⇒ Object (readonly)
Returns the value of attribute structure.
9 10 11 |
# File 'lib/vrt/map.rb', line 9 def structure @structure end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
9 10 11 |
# File 'lib/vrt/map.rb', line 9 def version @version end |
Instance Method Details
#categories ⇒ Object
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
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 |