Class: Glossarist::Transforms::ConceptToTbxTransform

Inherits:
Object
  • Object
show all
Defined in:
lib/glossarist/transforms/concept_to_tbx_transform.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(managed_concept, options = {}) ⇒ ConceptToTbxTransform

Returns a new instance of ConceptToTbxTransform.



35
36
37
38
# File 'lib/glossarist/transforms/concept_to_tbx_transform.rb', line 35

def initialize(managed_concept, options = {})
  @concept = managed_concept
  @options = options
end

Class Method Details

.transform(managed_concept, options = {}) ⇒ Object



8
9
10
# File 'lib/glossarist/transforms/concept_to_tbx_transform.rb', line 8

def self.transform(managed_concept, options = {})
  new(managed_concept, options).build_entry
end

.transform_document(concepts, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/glossarist/transforms/concept_to_tbx_transform.rb', line 12

def self.transform_document(concepts, options = {})
  doc = Tbx::Document.new
  body = Tbx::Body.new
  body.concept_entry = concepts.map { |c| transform(c, options) }
  text = Tbx::TextElement.new
  text.body = body
  doc.text = text

  if options[:title]
    header = doc.tbx_header || Tbx::TbxHeader.new
    file_desc = Tbx::FileDesc.new
    title_stmt = Tbx::TitleStmt.new
    title = Tbx::Title.new
    title.content = options[:title]
    title_stmt.title = title
    file_desc.title_stmt = title_stmt
    header.file_desc = file_desc
    doc.tbx_header = header
  end

  doc
end

Instance Method Details

#build_entryObject



40
41
42
43
44
45
# File 'lib/glossarist/transforms/concept_to_tbx_transform.rb', line 40

def build_entry
  entry = Tbx::ConceptEntry.new
  entry.id = concept_id
  entry.lang_sec = build_lang_sections
  entry
end