22
23
24
25
26
27
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
63
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
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
|
# File 'lib/natour/asciinurse.rb', line 22
def to_adoc(doc_root: '.', author: nil)
distance = ->(gps_track) { "#{gps_track.distance / 1000} km" if gps_track&.distance }
ascent = ->(gps_track) { "#{gps_track.ascent} m" if gps_track&.ascent }
descent = ->(gps_track) { "#{gps_track.descent} m" if gps_track&.descent }
title_image = images.find(&:landscape?)
doc = []
doc << "= #{title}"
doc << author if author
doc << ':revdate: {docdate}'
doc << ':figure-caption!:'
doc << ':table-caption!:'
doc << ':pdf-page-mode: none'
doc << ':title-page:'
if title_image
doc << ":title-image: #{Pathname(doc_root).join(title_image.path)}"
doc << ':title-logo-image: image::{title-image}[top=0%]'
doc << ''
doc << 'ifndef::backend-pdf[]'
doc << 'image::{title-image}[]'
doc << 'endif::[]'
end
doc << ''
doc << '<<<'
doc << ''
doc << '== Allgemein'
doc << ''
doc << '[cols="h,3"]'
doc << '|==='
doc << "|Datum |#{gps_track&.date&.strftime('%d.%m.%Y')}"
doc << "|Startzeit |#{gps_track&.start_point&.time&.strftime('%H:%M Uhr')}"
doc << "|Dauer |#{gps_track&.duration&.strftime('%th:%M h')}"
doc << "|Strecke |#{distance.call(gps_track)}"
doc << "|Aufstieg |#{ascent.call(gps_track)}"
doc << "|Abstieg |#{descent.call(gps_track)}"
doc << "|Ausgangsort|#{starting_point}"
doc << "|Ankunftsort|#{arrival_point}"
doc << '|Teilnehmer |'
doc << '|==='
doc << ''
if map_image
doc << "image::#{Pathname(doc_root).join(map_image.path)}[]"
doc << ''
end
doc << '<<<'
doc << ''
doc << '== Beschreibung'
doc << ''
doc << ''
doc << ''
unless images.empty?
doc << '<<<'
doc << ''
doc << '== Bilder'
doc << ''
images.each do |image|
width = if image.landscape?
'80%'
else
'40%'
end
doc << '.Abbildung {counter:image}'
doc << "image::#{Pathname(doc_root).join(image.path)}[width=#{width}]"
doc << ''
end
end
unless species_lists.empty?
doc << '<<<'
doc << ''
doc << '== Artenlisten'
doc << ''
index = 1
groups = species_lists.group_by(&:group)
[
OpenStruct.new(
group: :plants,
title: 'Pflanzenarten',
headers: ['Wissenschaftlicher Name', 'Deutscher Name'],
columns: %i[name name_de]
),
OpenStruct.new(
group: :birds,
title: 'Vogelarten',
headers: ['Deutscher Name', 'Wissenschaftlicher Name'],
columns: %i[name_de name]
)
].each do |info|
group = groups.fetch(info.group, [])
next if group.empty?
doc << "=== #{info.title}"
doc << ''
group.each do |species_list|
caption = '.Tabelle {counter:species_lists}'
caption << ": #{species_list.description}" if species_list.description
doc << caption
doc << '[cols="1,5,5",options=header]'
doc << '|==='
doc << "|Nr.|#{info..join('|')}"
species_list.each do |species|
doc <<
"|{counter:species_list#{index}}|#{info.columns.map { |method| species.public_send(method) }.join('|')}"
end
doc << '|==='
doc << ''
index += 1
end
end
end
doc.join("\n")
end
|