Method: Webgen::Page.parse_meta_info

Defined in:
lib/webgen/page.rb

.parse_meta_info(mi_data, has_mi_start) ⇒ Object

Parse the meta info string in mi_data and return the hash with the meta information. The original data is used for checking the validness of the meta information block.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/webgen/page.rb', line 45

def parse_meta_info(mi_data, has_mi_start)
  if mi_data.nil? && has_mi_start
    raise FormatError, 'Found start line for meta information block but no valid meta information block'
  elsif mi_data.nil?
    {}
  else
    begin
      meta_info = YAML::load(mi_data.to_s)
      unless meta_info.kind_of?(Hash)
        raise FormatError, "Invalid structure of meta information block: expected YAML hash but found #{meta_info.class}"
      end
    rescue ArgumentError, SyntaxError, YAML::SyntaxError => e
      raise FormatError, "Invalid YAML syntax in meta information block: #{e.message}"
    end
    meta_info
  end
end