Module: Keywords
- Defined in:
- lib/diml/elements/keywords.rb
Constant Summary collapse
Class Method Summary collapse
-
.build_from(content) ⇒ Object
Factory method to create a keyword from raw content.
-
.is_kw?(v) ⇒ Boolean
Returns whether or not the supplied value is a keyword.
Class Method Details
.build_from(content) ⇒ Object
Factory method to create a keyword from raw content
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/diml/elements/keywords.rb', line 17 def self.build_from(content) found_klasses = ALL.select do |kw| kw.try(content) end raise ArgumentError, "Provided content is not a keyword" if found_klasses.empty? klass = found_klasses.first # Split the content into two parts the keyword, and content. # @Example: Q. headingvalue -> [Q., headingvalue] _, remaining = content.split(klass.token) stripped = if remaining.nil? || remaining.empty? "" else remaining.strip end # Instantiate the keyword class with the content klass.new(stripped) end |
.is_kw?(v) ⇒ Boolean
Returns whether or not the supplied value is a keyword
42 43 44 45 46 |
# File 'lib/diml/elements/keywords.rb', line 42 def self.is_kw?(v) !ALL.select do |kw| kw.try(v) end.empty? end |