Class: CorrespondenceMarkup::StructureGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/correspondence-markup/types.rb

Overview

A structure group is a group of structures. Different structures in one structure group all represent the same information, but in different “languages”. Items different structures with the same item ID are shown in the UI as being translations of each other. (Items with the same ID in the same structure are also show as related, and are presumed to be separated components of a single virtual item.)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(structures) ⇒ StructureGroup

Initialize from the structures



219
220
221
# File 'lib/correspondence-markup/types.rb', line 219

def initialize(structures)
  @structures = structures
end

Instance Attribute Details

#structuresObject (readonly)

The array of structures



216
217
218
# File 'lib/correspondence-markup/types.rb', line 216

def structures
  @structures
end

Instance Method Details

#==(otherStructureGroup) ⇒ Object

A structure group is equal to another structure group that has the same structures



224
225
226
# File 'lib/correspondence-markup/types.rb', line 224

def ==(otherStructureGroup)
  otherStructureGroup.class == StructureGroup && otherStructureGroup.structures == @structures
end

#to_html(options = {}) ⇒ Object

Convert to HTML as a *<div>* of CSS class “structure-group” that contains the HTML outputs from the structures. Options for Helpers::text_to_html can be provided as single true/false value, or, as arrays of values, in which case the individual values are mapped to the corresponding structures.



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/correspondence-markup/types.rb', line 232

def to_html(options={})
  numStructures = structures.length
  structureOptions = Array.new(numStructures)
  for i in 0...numStructures do
    structureOptions[i] = {}
  end
  for key in options.keys do
    value = options[key]
    if value.kind_of? Array
      for i in 0...([value.length, numStructures].min) do
        structureOptions[i][key] = value[i]
      end
    else
      for i in 0...numStructures do
        structureOptions[i][key] = value
      end
    end
  end
  structureHtmls = (0...(structures.length)).map{|i| @structures[i].to_html(structureOptions[i])}
  "<div class=\"structure-group\">\n  " + 
    structureHtmls.join("").chomp("\n").gsub("\n", "\n  ") + 
    "\n</div>\n"
end