Module: ArticleJSON::Export::Common::HTML::Elements::Base::ClassMethods
- Defined in:
- lib/article_json/export/common/html/elements/base.rb
Instance Method Summary collapse
-
#base_class? ⇒ Boolean
Check if the current class is the base class a child class.
-
#build(element) ⇒ ArticleJSON::Export::Common::HTML::Elements::Base
Instantiate the correct sub class for a given element.
- #default_exporter_mapping ⇒ Object
-
#exporter_by_type(type) ⇒ ArticleJSON::Export::Common::HTML::Elements::Base
Look up the correct exporter class based on the element type.
Instance Method Details
#base_class? ⇒ Boolean
Check if the current class is the base class a child class. Since this common module is in a different namespace, a simple ‘self == Base` check does not work.
89 90 91 |
# File 'lib/article_json/export/common/html/elements/base.rb', line 89 def base_class? self == namespace::Base end |
#build(element) ⇒ ArticleJSON::Export::Common::HTML::Elements::Base
Instantiate the correct sub class for a given element
69 70 71 72 |
# File 'lib/article_json/export/common/html/elements/base.rb', line 69 def build(element) klass = exporter_by_type(element.type) klass.new(element) unless klass.nil? end |
#default_exporter_mapping ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/article_json/export/common/html/elements/base.rb', line 93 def default_exporter_mapping { text: namespace::Text, paragraph: namespace::Paragraph, heading: namespace::Heading, list: namespace::List, quote: namespace::Quote, image: namespace::Image, embed: namespace::Embed, text_box: namespace::TextBox, } end |
#exporter_by_type(type) ⇒ ArticleJSON::Export::Common::HTML::Elements::Base
Look up the correct exporter class based on the element type
77 78 79 80 81 82 83 |
# File 'lib/article_json/export/common/html/elements/base.rb', line 77 def exporter_by_type(type) key = type.to_sym custom_class = ArticleJSON.configuration.element_exporter_for( export_format, key ) custom_class || default_exporter_mapping[key] end |