Module: ArticleJSON::Export::Common::Elements::Base::ClassMethods
- Defined in:
- lib/article_json/export/common/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::Elements::Base
Instantiate the correct sub class for a given element.
- #default_exporter_mapping ⇒ Object
-
#exporter_by_type(type) ⇒ ArticleJSON::Export::Common::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.
63 64 65 |
# File 'lib/article_json/export/common/elements/base.rb', line 63 def base_class? self == namespace::Base end |
#build(element) ⇒ ArticleJSON::Export::Common::Elements::Base
Instantiate the correct sub class for a given element
43 44 45 46 |
# File 'lib/article_json/export/common/elements/base.rb', line 43 def build(element) klass = exporter_by_type(element.type) klass.new(element) unless klass.nil? end |
#default_exporter_mapping ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/article_json/export/common/elements/base.rb', line 67 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::Elements::Base
Look up the correct exporter class based on the element type
51 52 53 54 55 56 57 |
# File 'lib/article_json/export/common/elements/base.rb', line 51 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 |