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 in 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 shown as related, and are presumed to be different parts of a single virtual item.)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(structures) ⇒ StructureGroup

Initialize from the structures



234
235
236
# File 'lib/correspondence-markup/types.rb', line 234

def initialize(structures)
  @structures = structures
end

Instance Attribute Details

#structuresObject (readonly)

The array of structures



231
232
233
# File 'lib/correspondence-markup/types.rb', line 231

def structures
  @structures
end

Instance Method Details

#==(otherStructureGroup) ⇒ Object

A structure group is equal to another structure group that has the same structures (equality is only used for testing)



240
241
242
# File 'lib/correspondence-markup/types.rb', line 240

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.



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/correspondence-markup/types.rb', line 248

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