Class: Slaw::Grammars::Schedules::Schedule

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

Instance Method Summary collapse

Instance Method Details

#schedule_id(heading_text, i) ⇒ Object



84
85
86
# File 'lib/slaw/grammars/schedules_nodes.rb', line 84

def schedule_id(heading_text, i)
  heading_text.downcase().strip().gsub(/[^a-z0-9]/i, '').gsub(/ +/, '')
end

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



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/slaw/grammars/schedules_nodes.rb', line 88

def to_xml(b, idprefix=nil, i=1)
  # reset counters for this new schedule document
  Slaw::Grammars::Counters.reset!

  heading_text = self.schedule_title.heading_text
  if not heading_text
    heading_text = "Schedule"
    heading_text << " #{i}" if i > 1
  end

  # the schedule id is derived from the heading
  schedule_id = self.schedule_id(heading_text, i)
  eId = "att_#{i}"

  b.attachment(eId: eId) { |b|
    schedule_title.to_xml(b, '', heading_text)
    b.doc_(name: "schedule") { |b|
      b.meta { |b|
        b.identification(source: "#slaw") { |b|
          b.FRBRWork { |b|
            b.FRBRthis(value: "#{WORK_URI}/!#{schedule_id}")
            b.FRBRuri(value: WORK_URI)
            b.FRBRalias(value: heading_text)
            b.FRBRdate(date: '1980-01-01', name: 'Generation')
            b.FRBRauthor(href: '#council')
            b.FRBRcountry(value: 'za')
          }
          b.FRBRExpression { |b|
            b.FRBRthis(value: "#{EXPRESSION_URI}/!#{schedule_id}")
            b.FRBRuri(value: EXPRESSION_URI)
            b.FRBRdate(date: '1980-01-01', name: 'Generation')
            b.FRBRauthor(href: '#council')
            b.FRBRlanguage(language: 'eng')
          }
          b.FRBRManifestation { |b|
            b.FRBRthis(value: "#{MANIFESTATION_URI}/!#{schedule_id}")
            b.FRBRuri(value: MANIFESTATION_URI)
            b.FRBRdate(date: Time.now.strftime('%Y-%m-%d'), name: 'Generation')
            b.FRBRauthor(href: '#slaw')
          }
        }
      }

      b.mainBody { |b| 
        body.children.elements.each_with_index { |e| e.to_xml(b, eId + "__", i) } if body.is_a? Body
      }
    }
  }
end