module ArticleJSON::Export::Common::Elements::Base::ClassMethods

Public Instance Methods

base_class?() click to toggle source

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. @return [Boolean]

# File lib/article_json/export/common/elements/base.rb, line 63
def base_class?
  self == namespace::Base
end
build(element) click to toggle source

Instantiate the correct sub class for a given element @param [ArticleJSON::Elements::Base] element @return [ArticleJSON::Export::Common::Elements::Base]

# 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() click to toggle source
# 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) click to toggle source

Look up the correct exporter class based on the element type @param [Symbol] type @return [ArticleJSON::Export::Common::Elements::Base]

# 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