Class: Wikimovia::Formatters::LinkFormatter
- Inherits:
-
Object
- Object
- Wikimovia::Formatters::LinkFormatter
- Includes:
- Utilities
- Defined in:
- lib/wikimovia/formatters/link_formatter.rb
Constant Summary collapse
- PATTERN =
/\[\[(.*)\]\]/
- LINK_PATTERN =
/^.*\|(.*)$/
Class Method Summary collapse
Instance Method Summary collapse
-
#format(string) ⇒ Object
If the string provided is wrapped in ‘[[’ and ‘]]’, returns the contents of those wrappers.
Methods included from Utilities
#extract_pattern, template_regex
Class Method Details
.match?(string) ⇒ Boolean
10 11 12 |
# File 'lib/wikimovia/formatters/link_formatter.rb', line 10 def match?(string) string.match(PATTERN) ? true : false end |
Instance Method Details
#format(string) ⇒ Object
If the string provided is wrapped in ‘[[’ and ‘]]’, returns the contents of those wrappers. If it is of the format
- linked article|link name
-
it will return the link name.
18 19 20 21 22 23 24 25 26 |
# File 'lib/wikimovia/formatters/link_formatter.rb', line 18 def format(string) contents = extract_pattern(PATTERN, string) if contents.match(LINK_PATTERN) extract_pattern(LINK_PATTERN, contents) else contents end end |