Module: Mbrao::ContentInterface
- Extended by:
- ActiveSupport::Concern
- Included in:
- Content
- Defined in:
- lib/mbrao/content_interface.rb
Overview
Miscellaneous Content class methods.
Defined Under Namespace
Modules: ClassMethods
Constant Summary
- ALLOWED_DATETIME_FORMATS =
The allowed string format for a datetime.
[ "%Y%m%dT%H%M%S%z", "%Y%m%dT%H%M%S%Z", "%FT%T.%L%z", "%FT%T.%L%Z", "%FT%T%z", "%FT%T%Z", "%F %T %z", "%F %T %Z", "%F %T.%L %z", "%F %T.%L %Z", "%F %T.%L", "%F %T", "%F %H:%M", "%F", "%d/%m/%Y %T.%L", "%d/%m/%Y %T", "%d/%m/%Y %H:%M", "%d/%m/%Y" ].freeze
Instance Method Summary (collapse)
-
- (Hash) as_json(options = {})
Returns the content as an Hash.
-
- (Boolean) enabled_for_locales?(*locales)
Checks if the content is available for at least one of the provided locales.
-
- (String|HashWithIndifferentAccess) get_body(locales = [], engine = :plain_text)
Gets the body returning only the portion which are available for the given locales.
-
- (String|HashWithIndifferentAccess) get_more(locales = [])
Gets the “more link” text of the content in the desired locales.
-
- (Array|HashWithIndifferentAccess) get_tags(locales = [])
Gets the tags of the content in the desired locales.
-
- (String|HashWithIndifferentAccess) get_title(locales = [])
Gets the title of the content in the desired locales.
Instance Method Details
- (Hash) as_json(options = {})
Returns the content as an Hash.
106 107 108 109 |
# File 'lib/mbrao/content_interface.rb', line 106 def as_json( = {}) keys = [:uid, :locales, :title, :summary, :body, :tags, :more, :author, :created_at, :updated_at, :metadata] ::Mbrao::Parser.as_json(self, keys, ) end |
- (Boolean) enabled_for_locales?(*locales)
Checks if the content is available for at least one of the provided locales.
56 57 58 59 |
# File 'lib/mbrao/content_interface.rb', line 56 def enabled_for_locales?(*locales) locales = locales.flatten.ensure_array(flatten: true) { |l| l.ensure_string.strip }.reject { |l| l == "*" } @locales.blank? || locales.blank? || (@locales & locales).present? end |
- (String|HashWithIndifferentAccess) get_body(locales = [], engine = :plain_text)
Gets the body returning only the portion which are available for the given locales.
76 77 78 |
# File 'lib/mbrao/content_interface.rb', line 76 def get_body(locales = [], engine = :plain_text) Mbrao::Parser.create_engine(engine).filter_content(self, locales) end |
- (String|HashWithIndifferentAccess) get_more(locales = [])
Gets the “more link” text of the content in the desired locales.
94 95 96 |
# File 'lib/mbrao/content_interface.rb', line 94 def get_more(locales = []) filter_attribute_for_locales(@more, locales) end |
- (Array|HashWithIndifferentAccess) get_tags(locales = [])
Gets the tags of the content in the desired locales.
85 86 87 |
# File 'lib/mbrao/content_interface.rb', line 85 def (locales = []) filter_attribute_for_locales(@tags, locales) end |
- (String|HashWithIndifferentAccess) get_title(locales = [])
Gets the title of the content in the desired locales.
66 67 68 |
# File 'lib/mbrao/content_interface.rb', line 66 def get_title(locales = []) filter_attribute_for_locales(@title, locales) end |