Class: PetitFelix::Metadata

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

Instance Method Summary collapse

Instance Method Details

#get_image_location(img_dir, filename) ⇒ Object

Gets image from path and location



8
9
10
11
12
# File 'lib/felix/metadata.rb', line 8

def get_image_location img_dir, filename

  return File.join(img_dir,filename)

end

#get_metadata(input) ⇒ Object

Gets metadata from string into paired hashes



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/felix/metadata.rb', line 15

def (input)

  array = input.lines

   = {}

  array.each do |set|
  
    if set.count(":") >= 1
    
      data = set.split(":", 2)
      index = data[0].strip.downcase
      [index] = data[1].strip.gsub("\\\"", "\"")
      
    end
  end
  
  
end

#parse_property(string, base = "${x}") ⇒ Object

Transforms string into JSON parsed object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/felix/metadata.rb', line 51

def parse_property string, base="${x}"

  begin
  
    return JSON.parse(base.sub("${x}", string), symbolize_names: true)
    
  rescue
  
    return parse_property
    
  end
end

#split(input) ⇒ Object

Splits files into array into metadata strings and content



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/felix/metadata.rb', line 36

def split(input)

  input = input.split("---")
  
  if input.count > 1
  
    input = input.reject! { |s| s.nil? || s.empty? }
    
  end
  
  input
  
end