class CorrespondenceMarkup::Structure
A structure, containing a sequence of item groups, as well as a type and a description. A structure will be one of two or more in a “structure group”.
Attributes
A textual description of the type which will be displayed in the UI. E.g. “English”. Ideally it should be relatively concise. Can be nil.
The array of item groups that make up the content of the structure.
A short alphanumeric name for the type, typically reflecting the “language” of a structure where different structures in a group are different language versions of the same information. It is used to determine a CSS class of the structure. E.g. “english”. (It can be nil.)
Public Class Methods
Initialize from type, description and item groups
# File lib/correspondence-markup/types.rb, line 184 def initialize(type, description, item_groups) @type = type @description = description @item_groups = item_groups end
Public Instance Methods
A structure is equal to another structure with the same type, description and item groups (equality is only used for testing)
# File lib/correspondence-markup/types.rb, line 192 def ==(otherStructure) otherStructure.class == Structure && otherStructure.type == @type && otherStructure.description == description && otherStructure.item_groups == @item_groups end
From the type, determine the CSS class names to be used in the *<div>* element created by to_html. If there is no type, then just “structure”, otherwise, “structure <type>-structure”, e.g. if the type is “english”, then “structure english-structure”. (The “-structure” suffix is used to reduce the chance of accidental CSS class name collisions.)
# File lib/correspondence-markup/types.rb, line 202 def css_class_names class_names = "structure" if @type != "" and @type != nil class_names = "structure #{@type}-structure" end class_names end
Convert to HTML as a *<div>* with CSS class determined by css_class_names. Include a *<div>* of CSS class “language” (if the description is given) Include HTML for the item groups, converted according to the options for Helpers::text_to_html).
# File lib/correspondence-markup/types.rb, line 213 def to_html(options={}) itemGroupHtmls = @item_groups.map{|x| x.to_html(options)} "<div class=\"#{css_class_names}\">\n " + (@description ? "<div class=\"language\">#{@description}</div>\n " : "") + itemGroupHtmls.join("").chomp("\n").gsub("\n", "\n ") + "\n</div>\n" end