Class: CorrespondenceMarkup::Structure
- Inherits:
-
Object
- Object
- CorrespondenceMarkup::Structure
- Defined in:
- lib/correspondence-markup/types.rb
Overview
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”.
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
A textual description of the type which will be displayed in the UI.
-
#item_groups ⇒ Object
readonly
The array of item groups that make up the content of the structure.
-
#type ⇒ Object
readonly
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.
Instance Method Summary collapse
-
#==(otherStructure) ⇒ Object
A structure is equal to another structure with the same type, description and item groups (equality is only used for testing).
-
#css_class_names ⇒ Object
From the type, determine the CSS class names to be used in the *<div>* element created by to_html.
-
#initialize(type, description, item_groups) ⇒ Structure
constructor
Initialize from type, description and item groups.
-
#to_html(options = {}) ⇒ Object
Convert to HTML as a *<div>* with CSS class determined by css_class_names.
Constructor Details
#initialize(type, description, item_groups) ⇒ Structure
Initialize from type, description and item groups
184 185 186 187 188 |
# File 'lib/correspondence-markup/types.rb', line 184 def initialize(type, description, item_groups) @type = type @description = description @item_groups = item_groups end |
Instance Attribute Details
#description ⇒ Object (readonly)
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.
178 179 180 |
# File 'lib/correspondence-markup/types.rb', line 178 def description @description end |
#item_groups ⇒ Object (readonly)
The array of item groups that make up the content of the structure.
181 182 183 |
# File 'lib/correspondence-markup/types.rb', line 181 def item_groups @item_groups end |
#type ⇒ Object (readonly)
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.)
174 175 176 |
# File 'lib/correspondence-markup/types.rb', line 174 def type @type end |
Instance Method Details
#==(otherStructure) ⇒ Object
A structure is equal to another structure with the same type, description and item groups (equality is only used for testing)
192 193 194 195 196 |
# 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 ⇒ Object
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.)
202 203 204 205 206 207 208 |
# 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 = {}) ⇒ Object
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).
213 214 215 216 217 218 219 |
# File 'lib/correspondence-markup/types.rb', line 213 def to_html(={}) itemGroupHtmls = @item_groups.map{|x| x.to_html()} "<div class=\"#{css_class_names}\">\n " + (@description ? "<div class=\"language\">#{@description}</div>\n " : "") + itemGroupHtmls.join("").chomp("\n").gsub("\n", "\n ") + "\n</div>\n" end |