Class: Usmu::MetadataService

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(folder) ⇒ MetadataService

Returns a new instance of MetadataService.



6
7
8
# File 'lib/usmu/metadata_service.rb', line 6

def initialize(folder)
  @base = folder
end

Instance Attribute Details

#basevoid (readonly, private)

Returns the value of attribute base.



35
36
37
# File 'lib/usmu/metadata_service.rb', line 35

def base
  @base
end

Instance Method Details

#metadata(file) ⇒ void



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/usmu/metadata_service.rb', line 10

def (file)
  last_folder = file.rindex('/')
  base_meta = last_folder ? (file[0..(last_folder - 1)]) : {}

  metafile = if File.directory?(File.join(@base, file))
               file + '/meta.yml'
             else
               dot_position = File.basename(file).rindex('.')
               if (!dot_position.nil?) && dot_position > 0
                 file[0, file.rindex('.')] + '.meta.yml'
               else
                 file + '.meta.yml'
               end
             end

  metafile = File.join(@base, metafile)
  if File.exist? metafile
    base_meta.deep_merge! YAML.load_file(metafile)
  else
    base_meta
  end
end