Class: LowLoad::Metadata

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

Constant Summary collapse

EXTENSIONS =
[
  *::LowLoad::MarkdownAdapter::EXTENSIONS,
  *::LowLoad::RBXAdapter::EXTENSIONS,
  *::LowLoad::RubyAdapter::EXTENSIONS,
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMetadata

Returns a new instance of Metadata.



15
16
17
18
19
20
21
22
# File 'lib/metadata.rb', line 15

def initialize
  @loaded_paths = []
  @missed_paths = []

  @file_types = EXTENSIONS.each_with_object({}) { |extension, hash| hash[extension] = [] }
  @url_paths = {}
  @tags = {}
end

Instance Attribute Details

#file_typesObject

Returns the value of attribute file_types.



13
14
15
# File 'lib/metadata.rb', line 13

def file_types
  @file_types
end

#loaded_pathsObject

Returns the value of attribute loaded_paths.



13
14
15
# File 'lib/metadata.rb', line 13

def loaded_paths
  @loaded_paths
end

#missed_pathsObject

Returns the value of attribute missed_paths.



13
14
15
# File 'lib/metadata.rb', line 13

def missed_paths
  @missed_paths
end

#tagsObject

Returns the value of attribute tags.



13
14
15
# File 'lib/metadata.rb', line 13

def tags
  @tags
end

#url_pathsObject

Returns the value of attribute url_paths.



13
14
15
# File 'lib/metadata.rb', line 13

def url_paths
  @url_paths
end

Instance Method Details

#append(file_path:, adapter:, metadata:) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/metadata.rb', line 34

def append(file_path:, adapter:, metadata:)
  @loaded_paths << file_path
  @file_types[File.extname(file_path).delete_prefix('.')] << file_path
  @url_paths[adapter.url_path(file_path:)] = file_path

  [:tags]&.each do |tag|
    @tags[tag] ||= []
    @tags[tag] = file_path
  end
end

#process(file_path_adapters:) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/metadata.rb', line 24

def process(file_path_adapters:)
  file_path_adapters.each do |file_path, adapter|
    if ( = adapter&.(file_path:))
      append(file_path:, adapter:, metadata:)
    else
      @missed_paths << file_path
    end
  end
end