Class: PROIEL::Converter::Text

Inherits:
Object
  • Object
show all
Defined in:
lib/proiel/cli/converters/text.rb

Class Method Summary collapse

Class Method Details



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/proiel/cli/converters/text.rb', line 64

def print_diffable_div(div)
  current_citation = nil

  p = ''
  pb = div.presentation_before || ''

  div.sentences.each do |sentence|
    pb += sentence.presentation_before || ''

    sentence.tokens.each do |token|
      if token.has_content?
        if current_citation != token.citation_part
          puts p unless p.empty?
          p = "§#{token.citation_part.gsub(/\s+/, '_')} "
          current_citation = token.citation_part
        end

        p += [pb,
              token.presentation_before,
              token.form,
              token.presentation_after].compact.join
        pb = ''
      end
    end

    p += sentence.presentation_after unless sentence.presentation_after.nil?
  end

  p += div.presentation_after unless div.presentation_after.nil?

  puts p unless p.empty?
end


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/proiel/cli/converters/text.rb', line 28

def print_formatted_div(div)
  p = ''
  p += div.presentation_before unless div.presentation_before.nil?

  current_citation = nil

  div.sentences.each do |sentence|
    p += sentence.presentation_before unless sentence.presentation_before.nil?

    sentence.tokens.each do |token|
      if token.has_content?
        new_citation = token.citation_part

        if current_citation != new_citation
          p += "§#{new_citation.gsub(/\s+/, '_')} "
          current_citation = new_citation
        end

        p += [token.presentation_before,
              token.form,
              token.presentation_after].compact.join
      end
    end

    p += sentence.presentation_after unless sentence.presentation_after.nil?
  end

  p += div.presentation_after unless div.presentation_after.nil?

  p = p.strip.gsub(/ +/, ' ').split("\n").collect do |line|
      line.length > 80 ? line.gsub(/(.{1,80})(\s+|$)/, "\\1\n").strip : line
    end * "\n"

  puts p
end

.process(tb, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/proiel/cli/converters/text.rb', line 5

def process(tb, options)
  tb.sources.each do |source|
    puts "% id = #{source.id}"
    puts "% export_time = #{source.export_time}"
    puts "% title = #{source.title}"
    puts "% author = #{source.author}"
    puts "% citation_part = #{source.citation_part}"
    puts "% language = #{source.language}"

    source.divs.each do |div|
      puts
      puts "# #{div.title}"
      puts

      if options['diffable']
        print_diffable_div(div)
      else
        print_formatted_div(div)
      end
    end
  end
end