Class: Jekyll::GlossaryTooltip::OptionsParser
- Inherits:
-
Object
- Object
- Jekyll::GlossaryTooltip::OptionsParser
- Defined in:
- lib/jekyll-glossary_tooltip/options_parser.rb
Overview
Stripped down & modified version of github.com/ayastreb/jekyll-maps/blob/master/lib/jekyll-maps/options_parser.rb
Constant Summary collapse
- ARGS_PATTERN =
%r{\s*(\w[-_\w]*):\s*(\w[^,\n\r]*)}
- ARGS_ALLOWED =
%w[ display ].freeze
Class Method Summary collapse
Class Method Details
.parse(raw_options) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jekyll-glossary_tooltip/options_parser.rb', line 16 def parse() = { term_query: nil, display: nil } opt_segments = .strip.split(",") raise Errors::OptionsNoTermNameInTag unless opt_segments.length.positive? [:term_query] = opt_segments[0] opt_segments.shift parse_segments(, opt_segments) end |
.parse_segments(options, opt_segments) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jekyll-glossary_tooltip/options_parser.rb', line 30 def parse_segments(, opt_segments) opt_segments.each do |opt_segment| raise Errors::OptionsBadTagArgumentFormat, [:term_name] unless opt_segment =~ ARGS_PATTERN arg_name = Regexp.last_match(1) arg_value = Regexp.last_match(2) raise Errors::OptionsUnknownTagArgument, arg_name unless ARGS_ALLOWED.include?(arg_name) [arg_name.to_sym] = arg_value end end |