citeproc-rb 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +93 -0
- data/Rakefile +73 -0
- data/TODO +25 -0
- data/VERSION +1 -0
- data/data/locales/locales_en.xml +89 -0
- data/data/locales/locales_nl.xml +96 -0
- data/data/styles/ama.csl +184 -0
- data/data/styles/apa.csl +230 -0
- data/data/styles/apsa.csl +175 -0
- data/data/styles/asa.csl +215 -0
- data/data/styles/chicago-author-date.csl +361 -0
- data/data/styles/chicago-fullnote-bibliography.csl +665 -0
- data/data/styles/chicago-note-bibliography.csl +437 -0
- data/data/styles/chicago-note.csl +383 -0
- data/data/styles/harvard.csl +185 -0
- data/data/styles/ieee.csl +111 -0
- data/data/styles/mhra.csl +317 -0
- data/data/styles/mla.csl +173 -0
- data/data/styles/nature.csl +87 -0
- data/data/styles/nlm.csl +118 -0
- data/examples/citeproc_driver.rb +174 -0
- data/lib/citeproc.rb +28 -0
- data/lib/citeproc/csl.rb +647 -0
- data/lib/citeproc/csl_parser.rb +479 -0
- data/lib/citeproc/csl_processor.rb +485 -0
- data/lib/citeproc/csl_reference.rb +228 -0
- data/lib/citeproc/filters/bibo/bibo.rb +635 -0
- data/lib/citeproc/filters/bibo/bibo_input_filter.rb +242 -0
- data/lib/citeproc/filters/bibo/bibo_utils.rb +75 -0
- data/lib/citeproc/filters/csl_citation/csl_citation.rb +137 -0
- data/lib/citeproc/filters/csl_citation/csl_citation_input_filter.rb +274 -0
- data/lib/citeproc/formatters/base_formatter.rb +115 -0
- data/lib/citeproc/formatters/xhtml_formatter.rb +144 -0
- data/lib/citeproc/input_filter.rb +97 -0
- data/test/fixtures/bibo_test_data.n3 +191 -0
- data/test/fixtures/bibo_test_data.yaml +96 -0
- data/test/fixtures/bibo_test_how_to_cook.n3 +63 -0
- data/test/fixtures/bibo_test_zotero.rdf +129 -0
- data/test/fixtures/csl_test_data.json +62 -0
- data/test/fixtures/csl_test_data.yaml +8 -0
- data/test/fixtures/locales/test_locale_en.xml +89 -0
- data/test/fixtures/styles/test_csl_parse.csl +230 -0
- data/test/fixtures/styles/test_groups.csl +32 -0
- data/test/fixtures/styles/test_names.csl +46 -0
- data/test/fixtures/styles/test_sort.csl +125 -0
- data/test/fixtures/styles/test_text_terms.csl +40 -0
- data/test/test_all.rb +14 -0
- data/test/test_bibo.rb +20 -0
- data/test/test_csl.rb +136 -0
- data/test/test_csl_parser.rb +222 -0
- data/test/test_sample_bibo.rb +82 -0
- metadata +101 -0
data/lib/citeproc.rb
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# == About citeproc.rb
|
|
2
|
+
#
|
|
3
|
+
# All of Citeproc-rb's various part are loaded when you use <tt>require 'citeproc'</tt>.
|
|
4
|
+
#
|
|
5
|
+
# For a full list of features and instructions, see the README.
|
|
6
|
+
|
|
7
|
+
module Citeproc
|
|
8
|
+
VERSION = '0.1'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
begin
|
|
12
|
+
require 'rdf/redland'
|
|
13
|
+
rescue LoadError
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
require 'citeproc/csl'
|
|
18
|
+
require 'citeproc/csl_parser'
|
|
19
|
+
require 'citeproc/csl_processor'
|
|
20
|
+
require 'citeproc/csl_reference'
|
|
21
|
+
require 'citeproc/input_filter'
|
|
22
|
+
require 'citeproc/filters/csl_citation/csl_citation'
|
|
23
|
+
require 'citeproc/filters/csl_citation/csl_citation_input_filter'
|
|
24
|
+
require 'citeproc/filters/bibo/bibo'
|
|
25
|
+
require 'citeproc/filters/bibo/bibo_input_filter'
|
|
26
|
+
require 'citeproc/filters/bibo/bibo_utils'
|
|
27
|
+
require 'citeproc/formatters/base_formatter'
|
|
28
|
+
require 'citeproc/formatters/xhtml_formatter'
|
data/lib/citeproc/csl.rb
ADDED
|
@@ -0,0 +1,647 @@
|
|
|
1
|
+
# == Synopsis
|
|
2
|
+
#
|
|
3
|
+
# Defines the CSL object model, the core of the Ruby Citeproc system.
|
|
4
|
+
#
|
|
5
|
+
# == Author
|
|
6
|
+
#
|
|
7
|
+
# Liam Magee
|
|
8
|
+
#
|
|
9
|
+
# == Copyright
|
|
10
|
+
#
|
|
11
|
+
# Copyright (c) 2007, Liam Magee.
|
|
12
|
+
# Licensed under the same terms as Ruby - see http://www.ruby-lang.org/en/LICENSE.txt.
|
|
13
|
+
#
|
|
14
|
+
|
|
15
|
+
module Citeproc
|
|
16
|
+
|
|
17
|
+
# ---------- Modules -----------
|
|
18
|
+
|
|
19
|
+
# Mixin for formatting types
|
|
20
|
+
module Formatting
|
|
21
|
+
FORMATTING_TERMS = [
|
|
22
|
+
'prefix', 'suffix', 'font-family', 'font-style', 'font-variant', 'font-weight',
|
|
23
|
+
'text-decoration', 'text-transform', 'text-case', 'vertical-align', 'enforce-case',
|
|
24
|
+
'display', 'quotes'
|
|
25
|
+
]
|
|
26
|
+
attr_accessor :formatting
|
|
27
|
+
|
|
28
|
+
# Careful if using multiple mixins - other modules may use this too.
|
|
29
|
+
# How to delegate to other method_missing methods?
|
|
30
|
+
def method_missing(name, *args)
|
|
31
|
+
# Is a setter method?
|
|
32
|
+
n = name.to_s.gsub('_', '-')
|
|
33
|
+
if args and n.ends_with?('=')
|
|
34
|
+
formatting[n.sub('=', '')] = args
|
|
35
|
+
elsif formatting.has_key?(n)
|
|
36
|
+
formatting[n]
|
|
37
|
+
else
|
|
38
|
+
''
|
|
39
|
+
#raise NoMethodError
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Mixin for delimiter types
|
|
45
|
+
module Delimiter
|
|
46
|
+
DELIMITER_TERMS = [
|
|
47
|
+
'delimiter', 'delimiter-precedes-last'
|
|
48
|
+
]
|
|
49
|
+
attr_accessor :delimiters
|
|
50
|
+
|
|
51
|
+
# These methods are used since the method_missing method won't be called if the Formatting
|
|
52
|
+
# module takes precedence.
|
|
53
|
+
# TODO: Find a better way of handling this (a FormatterDelimiter module which overrides method_missing?)
|
|
54
|
+
def delimiter
|
|
55
|
+
delimiters[DELIMITER_TERMS[0]]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def delimiter=(value)
|
|
59
|
+
delimiters[DELIMITER_TERMS[0]] = value
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def delimiter_precedes_last
|
|
63
|
+
delimiters[DELIMITER_TERMS[1]]
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def delimiter_precedes_last=(value)
|
|
67
|
+
delimiters[DELIMITER_TERMS[1]] = value
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# ---------- Classes -----------
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# ---------- Style -----------
|
|
80
|
+
|
|
81
|
+
class Style
|
|
82
|
+
attr_accessor :class, :lang, :info, :terms, :macros, :citation, :bibliography
|
|
83
|
+
|
|
84
|
+
def initialize(style_class = 'in-text', lang = 'en', info = nil, terms = nil, macros = nil, citation = nil, bibliography = nil)
|
|
85
|
+
@style_class = style_class
|
|
86
|
+
@lang = lang
|
|
87
|
+
@info = info
|
|
88
|
+
@terms = terms
|
|
89
|
+
@macros = macros
|
|
90
|
+
@citation = citation
|
|
91
|
+
@bibliography = bibliography
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def add_macro macro
|
|
95
|
+
@macros = [] if !@macros
|
|
96
|
+
@macros << macro
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
# ---------- Info classes -----------
|
|
103
|
+
|
|
104
|
+
class Info
|
|
105
|
+
attr_accessor :authors, :categories, :contributors, :id, :links, :published, :rights, :source, :summary, :title, :updated
|
|
106
|
+
|
|
107
|
+
def initialize(id = nil, title = nil, updated = nil, authors = nil, categories = nil, contributors = nil, published = nil, links = nil, rights = nil, source = nil, summary = nil)
|
|
108
|
+
@id = id
|
|
109
|
+
@title = title
|
|
110
|
+
@updated = updated
|
|
111
|
+
@authors = authors ? authors : []
|
|
112
|
+
@categories = categories ? categories : []
|
|
113
|
+
@contributors = contributors ? contributors : []
|
|
114
|
+
@published = published
|
|
115
|
+
@links = links ? links : []
|
|
116
|
+
@rights = rights
|
|
117
|
+
@source = source
|
|
118
|
+
@summary = summary
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
# Handles CSL strings with language attributes
|
|
124
|
+
class InfoText
|
|
125
|
+
attr_accessor :text, :language
|
|
126
|
+
|
|
127
|
+
def initialize(text = nil, language = 'en')
|
|
128
|
+
@text = text
|
|
129
|
+
@language = language
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
class Agent
|
|
134
|
+
attr_accessor :name, :email, :uri
|
|
135
|
+
def initialize(name = nil, email = nil, uri = nil)
|
|
136
|
+
@name = name
|
|
137
|
+
@email = email
|
|
138
|
+
@uri = uri
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
class Author < Agent
|
|
143
|
+
def initialize(name = nil, email = nil, uri = nil)
|
|
144
|
+
super
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
class Contributor < Agent
|
|
149
|
+
def initialize(name = nil, email = nil, uri = nil)
|
|
150
|
+
super
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class Category
|
|
156
|
+
INFO_FIELDS = [
|
|
157
|
+
"anthropology", "biology", "botany", "chemistry", "engineering", "generic-base",
|
|
158
|
+
"geography", "geology", "history", "literature", "philosophy", "psychology",
|
|
159
|
+
"sociology", "political_science", "zoology" #, info-categories.extension
|
|
160
|
+
]
|
|
161
|
+
INFO_CLASSES = ["author-date", "numeric", "label", "note", "in-text"]
|
|
162
|
+
|
|
163
|
+
attr_accessor :term, :scheme, :label
|
|
164
|
+
def initialize(term = nil, scheme = nil, label = nil)
|
|
165
|
+
@term = term
|
|
166
|
+
@scheme = scheme
|
|
167
|
+
@label = label
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def is_standard_field?
|
|
171
|
+
INFO_FIELDS.include?(term)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def is_standard_class?
|
|
175
|
+
INFO_CLASSES.include?(term)
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
class GroupingElement
|
|
182
|
+
attr_accessor :elements
|
|
183
|
+
attr_reader :names, :labels, :dates, :texts, :groups, :conditionals
|
|
184
|
+
|
|
185
|
+
def initialize
|
|
186
|
+
@elements = []
|
|
187
|
+
@names = []
|
|
188
|
+
@labels = []
|
|
189
|
+
@dates = []
|
|
190
|
+
@texts = []
|
|
191
|
+
@groups = []
|
|
192
|
+
@conditionals = []
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def add_element(element)
|
|
196
|
+
@elements << element
|
|
197
|
+
case
|
|
198
|
+
when element.kind_of?(Names)
|
|
199
|
+
@names << element
|
|
200
|
+
when element.kind_of?(Date)
|
|
201
|
+
@dates << element
|
|
202
|
+
when element.kind_of?(Label)
|
|
203
|
+
@labels << element
|
|
204
|
+
when element.kind_of?(Text)
|
|
205
|
+
@texts << element
|
|
206
|
+
when element.kind_of?(Group)
|
|
207
|
+
@groups << element
|
|
208
|
+
when element.kind_of?(ConditionGroup)
|
|
209
|
+
@conditionals << element
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
alias << add_element
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
# ---------- Term classes -----------
|
|
219
|
+
|
|
220
|
+
class Terms
|
|
221
|
+
attr_accessor :locales
|
|
222
|
+
|
|
223
|
+
def initialize(locales = nil)
|
|
224
|
+
@locales = locales ? locales : []
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
def add_locale(locale)
|
|
228
|
+
@locales << locale
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
alias << add_locale
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
class Locale
|
|
236
|
+
attr_accessor :language, :terms
|
|
237
|
+
|
|
238
|
+
def initialize(language = nil, terms = nil)
|
|
239
|
+
@language = language
|
|
240
|
+
@terms = terms ? terms : []
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def add_term(term)
|
|
245
|
+
@terms << term
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def term_text(variable, form = nil, singular = true)
|
|
250
|
+
@terms.each do |term|
|
|
251
|
+
if variable == term.name
|
|
252
|
+
if !form or form == term.form
|
|
253
|
+
if term.kind_of? CompoundTerm
|
|
254
|
+
return (singular ? term.single : term.multiple)
|
|
255
|
+
else
|
|
256
|
+
return term.text
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
nil
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
alias << add_term
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
class Term
|
|
268
|
+
attr_accessor :form, :name, :include_period
|
|
269
|
+
|
|
270
|
+
def initialize(form = nil, name = nil, include_period = nil)
|
|
271
|
+
@form = form
|
|
272
|
+
@name = name
|
|
273
|
+
@include_period = include_period
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
# Redundant?
|
|
278
|
+
class SimpleTerm < Term
|
|
279
|
+
attr_accessor :text
|
|
280
|
+
|
|
281
|
+
def initialize(form = nil, name = nil, include_period = nil, text = nil)
|
|
282
|
+
super(form, name, include_period)
|
|
283
|
+
@text = text
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
alias value text
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
# Redundant?
|
|
290
|
+
class CompoundTerm < Term
|
|
291
|
+
attr_accessor :single, :multiple
|
|
292
|
+
|
|
293
|
+
def initialize(form = nil, name = nil, include_period = nil, single = nil, multiple = nil)
|
|
294
|
+
super(form, name, include_period)
|
|
295
|
+
@single = single
|
|
296
|
+
@multiple = multiple
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
# ---------- Macro classes -----------
|
|
303
|
+
|
|
304
|
+
class Macro < GroupingElement
|
|
305
|
+
attr_accessor :name
|
|
306
|
+
|
|
307
|
+
def initialize(name)
|
|
308
|
+
super()
|
|
309
|
+
@name = name
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
# ---------- Context (Citation and Bibliography) classes -----------
|
|
316
|
+
|
|
317
|
+
class Context
|
|
318
|
+
attr_accessor :options, :sort, :layout
|
|
319
|
+
def initialize(options = nil, sort = nil, layout = nil)
|
|
320
|
+
@options = options
|
|
321
|
+
@sort = sort
|
|
322
|
+
@layout = layout
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
def option(name)
|
|
326
|
+
options[name]
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
# Careful if using multiple mixins - other modules may use this too.
|
|
331
|
+
# How to delegate to other method_missing methods?
|
|
332
|
+
def method_missing(name, *args)
|
|
333
|
+
# Is a setter method?
|
|
334
|
+
n = name.to_s.gsub('_', '-')
|
|
335
|
+
if args and n.index('=') == n.length - 1
|
|
336
|
+
options[n.sub('=', '')] = args
|
|
337
|
+
elsif options.has_key?(n)
|
|
338
|
+
options[n]
|
|
339
|
+
else
|
|
340
|
+
raise NoMethodError
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
class CitationContext < Context
|
|
348
|
+
def initialize(options = nil, sort = nil, layout = nil)
|
|
349
|
+
super
|
|
350
|
+
end
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
class BibliographyContext < Context
|
|
355
|
+
def initialize(options = nil, sort = nil, layout = nil)
|
|
356
|
+
super
|
|
357
|
+
end
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
class Sort
|
|
362
|
+
attr_accessor :keys
|
|
363
|
+
|
|
364
|
+
def initialize
|
|
365
|
+
@keys = []
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
def add_key(key)
|
|
369
|
+
@keys << key
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
alias << add_key
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
# ---------- Layout classes -----------
|
|
377
|
+
|
|
378
|
+
class Layout < GroupingElement
|
|
379
|
+
include Formatting, Delimiter
|
|
380
|
+
|
|
381
|
+
def initialize(formatting = nil, delimiters = nil)
|
|
382
|
+
super()
|
|
383
|
+
@formatting = formatting
|
|
384
|
+
@delimiters = delimiters
|
|
385
|
+
end
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
# ---------- CSElement classes -----------
|
|
391
|
+
|
|
392
|
+
# Abstract class
|
|
393
|
+
class CSElement
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
# ---------- Name classes -----------
|
|
399
|
+
|
|
400
|
+
class ShortNames < CSElement
|
|
401
|
+
include Formatting, Delimiter
|
|
402
|
+
attr_accessor :variable
|
|
403
|
+
|
|
404
|
+
def initialize(formatting = nil, delimiters = nil, variable = nil)
|
|
405
|
+
@formatting = formatting
|
|
406
|
+
@delimiters = delimiters
|
|
407
|
+
@variable = variable
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
def == other
|
|
411
|
+
variable == other.variable if other.kind_of? ShortNames
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
alias value variable
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
class Names < ShortNames
|
|
418
|
+
attr_accessor :name, :labels, :substitute
|
|
419
|
+
|
|
420
|
+
def initialize(formatting = nil, delimiters = nil, variable = nil)
|
|
421
|
+
super(formatting, delimiters, variable)
|
|
422
|
+
@names = []
|
|
423
|
+
@labels = []
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
def add_label(name_label)
|
|
427
|
+
@labels << name_label
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
def each_label(&block)
|
|
431
|
+
@name_labels.each(block)
|
|
432
|
+
end
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
class Name
|
|
436
|
+
include Formatting, Delimiter
|
|
437
|
+
attr_accessor :form, :and, :delimiter_precedes_last, :name_as_sort_order, :sort_separator, :initialize_with
|
|
438
|
+
|
|
439
|
+
def initialize(formatting = nil, delimiters = nil,
|
|
440
|
+
form = nil, _and = nil, delimiter_precedes_last = nil,
|
|
441
|
+
name_as_sort_order = nil, sort_separator = nil, initialize_with = nil)
|
|
442
|
+
@formatting = formatting
|
|
443
|
+
@delimiters = delimiters
|
|
444
|
+
@form = form
|
|
445
|
+
@and = _and
|
|
446
|
+
@delimiter_precedes_last = delimiter_precedes_last
|
|
447
|
+
@name_as_sort_order = name_as_sort_order
|
|
448
|
+
@sort_separator = sort_separator
|
|
449
|
+
@initialize_with = initialize_with
|
|
450
|
+
end
|
|
451
|
+
end
|
|
452
|
+
|
|
453
|
+
class NameLabel < CSElement
|
|
454
|
+
include Formatting
|
|
455
|
+
attr_accessor :include_period, :form
|
|
456
|
+
|
|
457
|
+
def initialize(formatting = nil, include_period = nil, form = nil)
|
|
458
|
+
@formatting = formatting
|
|
459
|
+
@include_period = include_period
|
|
460
|
+
@form = form
|
|
461
|
+
end
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
class Substitute < GroupingElement
|
|
465
|
+
attr_accessor :names
|
|
466
|
+
|
|
467
|
+
def initialize
|
|
468
|
+
super
|
|
469
|
+
@names = []
|
|
470
|
+
end
|
|
471
|
+
|
|
472
|
+
# Overrides add_element to handle ShortNames
|
|
473
|
+
def add_element(element)
|
|
474
|
+
@elements << element
|
|
475
|
+
case
|
|
476
|
+
when element.kind_of?(Names)
|
|
477
|
+
@names << element
|
|
478
|
+
when element.kind_of?(Date)
|
|
479
|
+
@dates << element
|
|
480
|
+
when element.kind_of?(Label)
|
|
481
|
+
@labels << element
|
|
482
|
+
when element.kind_of?(Text)
|
|
483
|
+
@texts << element
|
|
484
|
+
when element.kind_of?(Group)
|
|
485
|
+
@groups << element
|
|
486
|
+
when element.kind_of?(ConditionGroup)
|
|
487
|
+
@conditionals << element
|
|
488
|
+
when element.kind_of?(ShortNames)
|
|
489
|
+
@names << element
|
|
490
|
+
end
|
|
491
|
+
end
|
|
492
|
+
|
|
493
|
+
alias << add_element
|
|
494
|
+
end
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
# ---------- Date classes -----------
|
|
499
|
+
|
|
500
|
+
class Date < CSElement
|
|
501
|
+
include Formatting, Delimiter
|
|
502
|
+
attr_accessor :variable, :dateparts
|
|
503
|
+
|
|
504
|
+
def initialize(formatting = nil, delimiters = nil, variable = nil)
|
|
505
|
+
@formatting = formatting
|
|
506
|
+
@delimiters = delimiters
|
|
507
|
+
@variable = variable
|
|
508
|
+
@dateparts = []
|
|
509
|
+
end
|
|
510
|
+
|
|
511
|
+
def add_datepart(datepart)
|
|
512
|
+
@dateparts << datepart
|
|
513
|
+
end
|
|
514
|
+
|
|
515
|
+
alias << add_datepart
|
|
516
|
+
alias value variable
|
|
517
|
+
end
|
|
518
|
+
|
|
519
|
+
class DatePart
|
|
520
|
+
include Formatting
|
|
521
|
+
attr_accessor :name, :form, :include_period
|
|
522
|
+
|
|
523
|
+
def initialize(formatting = nil, name = nil, form = nil, include_period = nil)
|
|
524
|
+
@formatting = formatting
|
|
525
|
+
@name = name
|
|
526
|
+
@form = form
|
|
527
|
+
@include_period = include_period
|
|
528
|
+
end
|
|
529
|
+
end
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
# ---------- Label class -----------
|
|
534
|
+
|
|
535
|
+
class Label < CSElement
|
|
536
|
+
include Formatting
|
|
537
|
+
attr_accessor :include_period, :form, :variable
|
|
538
|
+
|
|
539
|
+
def initialize(formatting = nil, include_period = nil, form = nil, variable = nil)
|
|
540
|
+
@formatting = formatting
|
|
541
|
+
@include_period = include_period
|
|
542
|
+
@form = form
|
|
543
|
+
@variable = variable
|
|
544
|
+
end
|
|
545
|
+
end
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
# ---------- Text classes -----------
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
class Text < CSElement
|
|
553
|
+
include Formatting
|
|
554
|
+
|
|
555
|
+
def initialize(formatting = nil)
|
|
556
|
+
@formatting = formatting
|
|
557
|
+
end
|
|
558
|
+
end
|
|
559
|
+
|
|
560
|
+
class VariableText < Text
|
|
561
|
+
include Delimiter
|
|
562
|
+
attr_accessor :variable
|
|
563
|
+
|
|
564
|
+
def initialize(formatting = nil, delimiters = nil, variable = nil)
|
|
565
|
+
#@formatting = formatting
|
|
566
|
+
super(formatting)
|
|
567
|
+
@delimiters = delimiters
|
|
568
|
+
@variable = variable
|
|
569
|
+
end
|
|
570
|
+
|
|
571
|
+
alias value variable
|
|
572
|
+
end
|
|
573
|
+
|
|
574
|
+
class MacroText < Text
|
|
575
|
+
attr_accessor :macro
|
|
576
|
+
|
|
577
|
+
def initialize(formatting = nil, macro = nil)
|
|
578
|
+
super(formatting)
|
|
579
|
+
@macro = macro
|
|
580
|
+
end
|
|
581
|
+
|
|
582
|
+
alias value macro
|
|
583
|
+
end
|
|
584
|
+
|
|
585
|
+
class TermText < Text
|
|
586
|
+
attr_accessor :term
|
|
587
|
+
|
|
588
|
+
def initialize(formatting = nil, term = nil)
|
|
589
|
+
super(formatting)
|
|
590
|
+
@term = term
|
|
591
|
+
end
|
|
592
|
+
|
|
593
|
+
alias value term
|
|
594
|
+
end
|
|
595
|
+
|
|
596
|
+
class ValueText < Text
|
|
597
|
+
attr_accessor :value
|
|
598
|
+
|
|
599
|
+
def initialize(formatting = nil, value = nil)
|
|
600
|
+
super(formatting)
|
|
601
|
+
@value = value
|
|
602
|
+
end
|
|
603
|
+
end
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
# ---------- Group classes -----------
|
|
608
|
+
|
|
609
|
+
class Group < GroupingElement
|
|
610
|
+
include Formatting, Delimiter
|
|
611
|
+
attr_reader :class_name
|
|
612
|
+
|
|
613
|
+
def initialize(formatting = nil, delimiters = nil, class_name = nil)
|
|
614
|
+
super()
|
|
615
|
+
@formatting = formatting
|
|
616
|
+
@delimiters = delimiters
|
|
617
|
+
@class_name = class_name
|
|
618
|
+
end
|
|
619
|
+
end
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
# ---------- Condition classes -----------
|
|
624
|
+
|
|
625
|
+
class ConditionGroup
|
|
626
|
+
include Enumerable
|
|
627
|
+
attr_accessor :conditions
|
|
628
|
+
|
|
629
|
+
def initialize
|
|
630
|
+
@conditions = []
|
|
631
|
+
end
|
|
632
|
+
|
|
633
|
+
def add_condition(condition)
|
|
634
|
+
@conditions << condition
|
|
635
|
+
end
|
|
636
|
+
|
|
637
|
+
def each(&block)
|
|
638
|
+
@conditions.each(&block) if @conditions
|
|
639
|
+
end
|
|
640
|
+
|
|
641
|
+
alias << add_condition
|
|
642
|
+
end
|
|
643
|
+
|
|
644
|
+
class Condition < GroupingElement
|
|
645
|
+
attr_accessor :type, :variable, :position, :disambiguate, :locator, :match
|
|
646
|
+
end
|
|
647
|
+
end
|