Class: AsciiBinderGabrielRH::TopicMap

Inherits:
Object
  • Object
show all
Defined in:
lib/ascii_binder_gabriel_rh/topic_map.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(topic_file, distro_keys) ⇒ TopicMap

Returns a new instance of TopicMap.



12
13
14
15
16
17
18
19
20
# File 'lib/ascii_binder_gabriel_rh/topic_map.rb', line 12

def initialize(topic_file,distro_keys)
  @topic_yaml  = YAML.load_stream(open(topic_file))
  @distro_keys = distro_keys
  @list        = []
  @topic_yaml.each do |topic_entity|
    @list << AsciiBinderGabrielRH::TopicEntity.new(topic_entity,distro_keys)
  end

end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



10
11
12
# File 'lib/ascii_binder_gabriel_rh/topic_map.rb', line 10

def list
  @list
end

Instance Method Details

#alias_list(distro_key) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/ascii_binder_gabriel_rh/topic_map.rb', line 42

def alias_list(distro_key)
  alias_list = []
  @list.each do |topic_entity|
    alias_sublist = topic_entity.alias_list(distro_key)
    next if alias_sublist.empty?
    alias_list.push(*alias_sublist)
  end
  return alias_list
end

#errorsObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ascii_binder_gabriel_rh/topic_map.rb', line 80

def errors
  errors = []
  @list.each do |topic_entity|
    if not topic_entity.is_group?
      errors << "Top-level entries in the topic map must all be topic groups. Entity with name '#{topic_entity.name}' is not a group."
      next
    end
    next if topic_entity.is_valid?
    errors << topic_entity.errors
  end
  # Test all aliases
  @distro_keys.each do |distro_key|
    distro_aliases = alias_list(distro_key)
    distro_paths   = path_list(distro_key)
    distro_aliases.each do |alias_map|
      if distro_paths.include?(alias_map[:alias_path])
        errors << "An actual topic file and a topic alias both exist at the same path '#{alias_map[:alias_path]}' for distro '#{distro_key}'"
      end
      next if valid_url?(alias_map[:redirect_path])
      if not distro_paths.include?(alias_map[:redirect_path])
        errors << "Topic alias '#{alias_map[:alias_path]}' points to a nonexistent topic '#{alias_map[:redirect_path]}' for distro '#{distro_key}'"
      end
    end
  end
  return errors
end

#filepathsObject



22
23
24
25
26
27
28
29
30
# File 'lib/ascii_binder_gabriel_rh/topic_map.rb', line 22

def filepaths
  @filepaths ||= begin
    filepaths = []
    @list.each do |topic_entity|
      filepaths.concat(topic_entity.group_filepaths)
    end
    filepaths
  end
end

#is_valid?Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ascii_binder_gabriel_rh/topic_map.rb', line 62

def is_valid?
  @list.each do |topic_entity|
    next if topic_entity.is_valid? and topic_entity.is_group?
    return false
  end
  # Test all aliases
  @distro_keys.each do |distro_key|
    distro_aliases = alias_list(distro_key)
    distro_paths   = path_list(distro_key)
    distro_aliases.each do |alias_map|
      return false if distro_paths.include?(alias_map[:alias_path])
      next if valid_url?(alias_map[:redirect_path])
      return false unless distro_paths.include?(alias_map[:redirect_path])
    end
  end
  return true
end


32
33
34
35
36
37
38
39
40
# File 'lib/ascii_binder_gabriel_rh/topic_map.rb', line 32

def nav_tree(distro_key)
  nav_tree = []
  @list.each do |topic_entity|
    entity_nav = topic_entity.nav_tree(distro_key)
    next if entity_nav.empty?
    nav_tree << entity_nav
  end
  return nav_tree
end

#path_list(distro_key) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/ascii_binder_gabriel_rh/topic_map.rb', line 52

def path_list(distro_key)
  path_list = []
  @list.each do |topic_entity|
    path_sublist = topic_entity.path_list(distro_key)
    next if path_sublist.empty?
    path_list.push(*path_sublist)
  end
  return path_list
end