Class: CorrespondenceMarkup::ItemGroup
- Inherits:
-
Object
- Object
- CorrespondenceMarkup::ItemGroup
- Defined in:
- lib/correspondence-markup/types.rb
Overview
A group of items & non-items that will form part of a structure. Typically an item group is one line of items (i.e. words) and non-items, or maybe two or three lines which naturally group together within the overall structure (and which cannot be separated because they translate to a single line in one of the other structures in the same structure group). Item groups with the same ID in different structures in the same structure group are related to each other, and may be shown next to each other in the UI when the “Interleave” option is chosen.
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
The array of items and non-items.
-
#id ⇒ Object
readonly
The ID which is unique in the structure.
Instance Method Summary collapse
-
#==(otherItemGroup) ⇒ Object
An item group is equal to another item group with the same IDs and the same content (equality is only used for testing).
-
#initialize(id, content) ⇒ ItemGroup
constructor
Initialize from ID and array of items and non-items.
-
#to_html(options = {}) ⇒ Object
Convert to HTML as a *<div>* tag with class item-group, data-group-id attribute equal to the ID, and containing the HTML output for the content items and non-items (with those converted according to the options for Helpers::text_to_html).
Constructor Details
#initialize(id, content) ⇒ ItemGroup
Initialize from ID and array of items and non-items
147 148 149 150 |
# File 'lib/correspondence-markup/types.rb', line 147 def initialize(id, content) @id = id @content = content end |
Instance Attribute Details
#content ⇒ Object (readonly)
The array of items and non-items
144 145 146 |
# File 'lib/correspondence-markup/types.rb', line 144 def content @content end |
#id ⇒ Object (readonly)
The ID which is unique in the structure. It identifies the item group uniquely within the structure. It also serves as a default prefix when parsing IDs for individual items.
141 142 143 |
# File 'lib/correspondence-markup/types.rb', line 141 def id @id end |
Instance Method Details
#==(otherItemGroup) ⇒ Object
An item group is equal to another item group with the same IDs and the same content (equality is only used for testing)
154 155 156 |
# File 'lib/correspondence-markup/types.rb', line 154 def ==(otherItemGroup) otherItemGroup.class == ItemGroup && otherItemGroup.id == @id && otherItemGroup.content == @content end |
#to_html(options = {}) ⇒ Object
Convert to HTML as a *<div>* tag with class item-group, data-group-id attribute equal to the ID, and containing the HTML output for the content items and non-items (with those converted according to the options for Helpers::text_to_html).
161 162 163 164 |
# File 'lib/correspondence-markup/types.rb', line 161 def to_html(={}) "<div class=\"item-group\" data-group-id=\"#{@id}\">\n " + @content.map{|x| x.to_html()}.join("") + "\n</div>\n" end |