Class: Jekyll::Maps::OptionsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-maps/options_parser.rb

Constant Summary collapse

OPTIONS_SYNTAX =
%r!([^\s]+)\s*=\s*['"]+([^'"]+)['"]+!
ALLOWED_FLAGS =
%w(
  no_cluster
).freeze
ALLOWED_ATTRIBUTES =
%w(
  id
  width
  height
  class
  show_marker
  show_popup
  zoom
  latitude
  longitude
  marker_title
  marker_icon
  marker_img
  marker_url
  marker_popup_html
  styles
).freeze

Class Method Summary collapse

Class Method Details

.parse(raw_options) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jekyll-maps/options_parser.rb', line 27

def parse(raw_options)
  options = {
    :attributes => {},
    :filters    => {},
    :flags      => {}
  }
  raw_options.scan(OPTIONS_SYNTAX).each do |key, value|
    value = value.split(",") if value.include?(",")
    if ALLOWED_ATTRIBUTES.include?(key)
      options[:attributes][key.to_sym] = value
    else
      options[:filters][key] = value
    end
  end
  ALLOWED_FLAGS.each do |key|
    options[:flags][key.to_sym] = true if raw_options.include?(key)
  end
  options
end