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

description[R]

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.

item_groups[R]

The array of item groups that make up the content of the structure.

type[R]

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

new(type, description, item_groups) click to toggle source

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

==(otherStructure) click to toggle source

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

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
to_html(options={}) click to toggle source

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