Class: Wikimovia::TemplateExtractor
- Inherits:
-
Object
- Object
- Wikimovia::TemplateExtractor
- Includes:
- Utilities
- Defined in:
- lib/wikimovia/template_extractor.rb
Instance Method Summary collapse
-
#extract_first(string, options = {}) ⇒ Object
Given some wikitext syntax, and a :template_name, extracts the first template with that name it can find and converts it to a Hash.
Methods included from Utilities
#extract_pattern, template_regex
Instance Method Details
#extract_first(string, options = {}) ⇒ Object
Given some wikitext syntax, and a :template_name, extracts the first template with that name it can find and converts it to a Hash.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/wikimovia/template_extractor.rb', line 7 def extract_first(string, = {}) pattern = Wikimovia::Utilities.template_regex [:template_name], use_vertical_bar: false wikitext = WikiCloth::Parser.new(data: string).to_wikitext template = extract_pattern(pattern, wikitext) if template info_lines = extract_info_lines(template) split_lines = (info_lines) cleaned_lines = (split_lines) filtered_lines = (cleaned_lines) hash = Hash[*filtered_lines.flatten] hash.keys.each do |key| hash[(key.to_sym rescue key) || key] = hash.delete(key) end hash end end |