Class: Slaw::ZA::Act::Schedule

Inherits:
Treetop::Runtime::SyntaxNode
  • Object
show all
Defined in:
lib/slaw/za/act_nodes.rb

Instance Method Summary collapse

Instance Method Details

#aliasObject



423
424
425
426
427
428
429
430
431
# File 'lib/slaw/za/act_nodes.rb', line 423

def alias
  if not schedule_title.title.text_value.blank?
    schedule_title.title.text_value
  elsif num
    "Schedule #{num}"
  else
    "Schedule"
  end
end

#headingObject



433
434
435
436
437
438
439
# File 'lib/slaw/za/act_nodes.rb', line 433

def heading
  if schedule_title.heading.respond_to? :content
    schedule_title.heading.content.text_value
  else
    nil
  end
end

#numObject



418
419
420
421
# File 'lib/slaw/za/act_nodes.rb', line 418

def num
  n = schedule_title.num.text_value
  return (n && !n.empty?) ? n : nil
end

#to_xml(b, idprefix = nil, i = 1) ⇒ Object



441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/slaw/za/act_nodes.rb', line 441

def to_xml(b, idprefix=nil, i=1)
  if num
    n = num
    component = "schedule#{n}"
  else
    n = i
    # make a component name from the schedule title
    component = self.alias.downcase().strip().gsub(/[^a-z0-9]/i, '').gsub(/ +/, '')
  end

  id = "#{idprefix}#{component}"

  b.component(id: "component-#{id}") { |b|
    b.doc_(name: component) { |b|
      b.meta { |b|
        b.identification(source: "#slaw") { |b|
          b.FRBRWork { |b|
            b.FRBRthis(value: "#{Act::WORK_URI}/#{component}")
            b.FRBRuri(value: Act::WORK_URI)
            b.FRBRalias(value: self.alias)
            b.FRBRdate(date: '1980-01-01', name: 'Generation')
            b.FRBRauthor(href: '#council')
            b.FRBRcountry(value: 'za')
          }
          b.FRBRExpression { |b|
            b.FRBRthis(value: "#{Act::EXPRESSION_URI}/#{component}")
            b.FRBRuri(value: Act::EXPRESSION_URI)
            b.FRBRdate(date: '1980-01-01', name: 'Generation')
            b.FRBRauthor(href: '#council')
            b.FRBRlanguage(language: 'eng')
          }
          b.FRBRManifestation { |b|
            b.FRBRthis(value: "#{Act::MANIFESTATION_URI}/#{component}")
            b.FRBRuri(value: Act::MANIFESTATION_URI)
            b.FRBRdate(date: Time.now.strftime('%Y-%m-%d'), name: 'Generation')
            b.FRBRauthor(href: '#slaw')
          }
        }
      }

      b.mainBody { |b| 
        idprefix = "#{id}."

        # there is no good AKN hierarchy container for schedules, so we
        # just use article because we don't use it anywhere else.
        b.article(id: id) { |b|
          b.heading(heading) if heading
          body.children.elements.each_with_index { |e| e.to_xml(b, idprefix, i) } if body.is_a? Body
        }
      }
    }
  }
end