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
23
# File 'lib/metadata.rb', line 15

def initialize
  @file_paths = []

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

  @tags = {}
end

Instance Attribute Details

#file_pathsObject

Returns the value of attribute file_paths.



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

def file_paths
  @file_paths
end

#file_typesObject

Returns the value of attribute file_types.



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

def file_types
  @file_types
end

#tagsObject

Returns the value of attribute tags.



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

def tags
  @tags
end

Instance Method Details

#append(metadata:) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/metadata.rb', line 41

def append(metadata:)
  @file_paths << [:file_path]
  @file_types[[:file_type]] = [:file_path]

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

#process(file_path_adapters:) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/metadata.rb', line 25

def process(file_path_adapters:)
  file_path_adapters.each do |file_path, adapter|
    if ( = adapter&.(file_path:))
      .merge!({
        file_path:,
        file_type: File.extname(file_path).delete_prefix('.'),
        file_loaded: true,
      })
    else
       = { file_loaded: false }
    end

    append(metadata:)
  end
end