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.
-
#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
170 171 172 173 174 |
# File 'lib/correspondence-markup/types.rb', line 170 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.
164 165 166 |
# File 'lib/correspondence-markup/types.rb', line 164 def description @description end |
#item_groups ⇒ Object (readonly)
The array of item groups that make up the content of the structure.
167 168 169 |
# File 'lib/correspondence-markup/types.rb', line 167 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.)
160 161 162 |
# File 'lib/correspondence-markup/types.rb', line 160 def type @type end |
Instance Method Details
#==(otherStructure) ⇒ Object
A structure is equal to another structure with the same type, description and item groups
177 178 179 180 181 |
# File 'lib/correspondence-markup/types.rb', line 177 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.)
187 188 189 190 191 192 193 |
# File 'lib/correspondence-markup/types.rb', line 187 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).
198 199 200 201 202 203 204 |
# File 'lib/correspondence-markup/types.rb', line 198 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 |