module Mbrao::ContentInterface
Miscellaneous {Content Content} class methods.
Constants
- ALLOWED_DATETIME_FORMATS
The allowed string format for a datetime.
Public Instance Methods
Returns the content as an Hash.
@param options [Hash] Options to modify behavior of the serialization.
The only supported value are: * `:exclude`, an array of attributes to skip. * `:exclude_empty`, if to exclude nil values. Default is `false`.
@return [Hash] An hash with all attributes.
# File lib/mbrao/content_interface.rb, line 106 def as_json(options = {}) keys = [:uid, :locales, :title, :summary, :body, :tags, :more, :author, :created_at, :updated_at, :metadata] ::Mbrao::Parser.as_json(self, keys, options) end
Checks if the content is available for at least one of the provided locales.
@param locales [Array] The desired locales. Can include `*` to match all. If none are specified, the default mbrao locale will be used. @return [Boolean] `true` if the content is available for at least one of the desired locales, `false` otherwise.
# 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
Gets the body returning only the portion which are available for the given locales.
@param locales [String|Array] The desired locales. Can include `*` to match all. If none are specified, the default mbrao locale will be used. @param engine [String|Symbol|Object] The engine to use to filter contents. @return [String|HashWithIndifferentAccess] Return the body of the content in the desired locales. If only one locale is required, then a `String`
is returned, else a `HashWithIndifferentAccess` with locales as keys.
# 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
Gets the “more link” text of the content in the desired locales.
@param locales [String|Array] The desired locales. Can include `*` to match all. If none are specified, the default mbrao locale will be used. @return [String|HashWithIndifferentAccess] Return the label of the “more link” of the content in the desired locales. If only one locale is required,
then a `String` is returned, else a `HashWithIndifferentAccess` with locales as keys.
# File lib/mbrao/content_interface.rb, line 94 def get_more(locales = []) filter_attribute_for_locales(@more, locales) end
Gets the title of the content in the desired locales.
@param locales [String|Array] The desired locales. Can include `*` to match all. If none are specified, the default mbrao locale will be used. @return [String|HashWithIndifferentAccess] Return the title of the content in the desired locales. If only one locale is required, then a `String`
is returned, else a `HashWithIndifferentAccess` with locales as keys.
# File lib/mbrao/content_interface.rb, line 66 def get_title(locales = []) filter_attribute_for_locales(@title, locales) end