natour 0.4.0 → 0.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 731b0453c6a936a6207ce9802c212ed6747631eaedac2c88becc01420774f066
4
- data.tar.gz: b8558c8228ddc650b44c92632f55d44737cdb9f5ac2114e1b472b8cb860d12d2
3
+ metadata.gz: b125a5ba293c91fa5efcb56ee32bc6e5ed52c1b8daf82439bcbec6c7b279a29d
4
+ data.tar.gz: bda03749fc2db89b56adadbb8bfb1522b8e116d294be244f918f9a6142005d07
5
5
  SHA512:
6
- metadata.gz: a866a26f237240eeb30e6b4ca8aa5e82c1bfb7db472d18951a5fccb6e3c873f6b0683b9c04bfe60202d81442edb3205e7b8a7d44dd4eddad09329c1a4d181d9e
7
- data.tar.gz: f181d95ffb4df6445c649a51b6d762bd8d801ccfcdc57c616e8dad7cb30f5b52afe5daf294c1ae76c4ecec9efa719f03dbceae84dd9db7a2fdbfbed870d97f09
6
+ metadata.gz: c3ddac7902534aec8e14fb546287a45d6fd589c3b4c445b1291bef15d209b7eb9c43484f169ee7e3b9dcac44939b57f4d19d6fae07a261edf6d12499af11d16a
7
+ data.tar.gz: e1eebd6fa2c8704e25afe48c2120a146d0513f17a55df883d68aad05bbedd08e04173455119abe06ab8ef15894358b650a5590be74435ffd166f27e698c6aef6
data/CHANGELOG.adoc CHANGED
@@ -6,6 +6,19 @@ The format is based on https://keepachangelog.com/en/1.0.0/[Keep a Changelog^],
6
6
 
7
7
  == Unreleased
8
8
 
9
+ == 0.5.0 - 2021-08-16
10
+
11
+ === Added
12
+
13
+ - Reflect the date of the last update in the revision date
14
+ - Add captions to species lists in the AsciiDoc output
15
+ - Group species lists by taxonomic groups in the AsciiDoc output
16
+
17
+ === Fixed
18
+
19
+ - Support species lists of Flora Helvetica exported from Favoriten
20
+ - Consider botanical names with the authority name preceding the subspecies
21
+
9
22
  == 0.4.0 - 2021-05-02
10
23
 
11
24
  === Added
data/lib/natour.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'natour/utils/botanical_name_utils'
1
2
  require 'natour/utils/date_utils'
2
3
  require 'natour/utils/stdout_utils'
3
4
  require 'natour/convert'
@@ -30,9 +30,10 @@ module Natour
30
30
  doc << "= #{title}"
31
31
  if author
32
32
  doc << author
33
- doc << Date.today.strftime('%d.%m.%Y')
33
+ doc << ':revdate: {docdate}'
34
34
  end
35
35
  doc << ':figure-caption!:'
36
+ doc << ':table-caption!:'
36
37
  doc << ':pdf-page-mode: none'
37
38
  doc << ':title-page:'
38
39
  if title_image
@@ -88,35 +89,45 @@ module Natour
88
89
  end
89
90
  end
90
91
  unless species_lists.empty?
91
- birds_info = OpenStruct.new(
92
- title: 'Vogelarten',
93
- headers: %w[Deutscher\ Name Wissenschaftlicher\ Name],
94
- columns: %i[name_de name]
95
- )
96
- plants_info = OpenStruct.new(
97
- title: 'Pflanzenarten',
98
- headers: %w[Wissenschaftlicher\ Name Deutscher\ Name],
99
- columns: %i[name name_de]
100
- )
101
92
  doc << '<<<'
102
93
  doc << ''
103
94
  doc << '== Artenlisten'
104
95
  doc << ''
105
- species_lists.each.with_index(1) do |species_list, index|
106
- info = {
107
- birds: birds_info,
108
- plants: plants_info
109
- }[species_list.group]
96
+ index = 1
97
+ groups = species_lists.group_by(&:group)
98
+ [
99
+ OpenStruct.new(
100
+ group: :plants,
101
+ title: 'Pflanzenarten',
102
+ headers: %w[Wissenschaftlicher\ Name Deutscher\ Name],
103
+ columns: %i[name name_de]
104
+ ),
105
+ OpenStruct.new(
106
+ group: :birds,
107
+ title: 'Vogelarten',
108
+ headers: %w[Deutscher\ Name Wissenschaftlicher\ Name],
109
+ columns: %i[name_de name]
110
+ )
111
+ ].each do |info|
112
+ group = groups.fetch(info.group, [])
113
+ next if group.empty?
114
+
110
115
  doc << "=== #{info.title}"
111
116
  doc << ''
112
- doc << '[cols="1,5,5",options=header]'
113
- doc << '|==='
114
- doc << "|Nr.|#{info.headers.join('|')}"
115
- species_list.each do |species|
116
- doc << "|{counter:species_list#{index}}|#{info.columns.map { |method| species.send(method) }.join('|')}"
117
+ group.each do |species_list|
118
+ caption = '.Tabelle {counter:species_lists}'
119
+ caption << ": #{species_list.description}" if species_list.description
120
+ doc << caption
121
+ doc << '[cols="1,5,5",options=header]'
122
+ doc << '|==='
123
+ doc << "|Nr.|#{info.headers.join('|')}"
124
+ species_list.each do |species|
125
+ doc << "|{counter:species_list#{index}}|#{info.columns.map { |method| species.send(method) }.join('|')}"
126
+ end
127
+ doc << '|==='
128
+ doc << ''
129
+ index += 1
117
130
  end
118
- doc << '|==='
119
- doc << ''
120
131
  end
121
132
  end
122
133
  doc.join("\n")
@@ -3,6 +3,7 @@ require 'pathname'
3
3
  require 'asciidoctor'
4
4
  require 'asciidoctor-pdf'
5
5
  require 'vips'
6
+ require 'time'
6
7
 
7
8
  module Natour
8
9
  module_function
@@ -41,6 +42,25 @@ module Natour
41
42
  end
42
43
  end
43
44
 
45
+ %w[
46
+ revdate
47
+ docdate
48
+ doctime
49
+ docdatetime
50
+ localdate
51
+ localtime
52
+ localdatetime
53
+ ].each do |attr_name|
54
+ date_time = Time.parse(doc.attr(attr_name))
55
+ if attr_name.end_with?('datetime')
56
+ doc.set_attr(attr_name, date_time.strftime('%d.%m.%Y %H:%M:%S'))
57
+ elsif attr_name.end_with?('date')
58
+ doc.set_attr(attr_name, date_time.strftime('%d.%m.%Y'))
59
+ elsif attr_name.end_with?('time')
60
+ doc.set_attr(attr_name, date_time.strftime('%H:%M:%S'))
61
+ end
62
+ end
63
+
44
64
  if backend == 'pdf'
45
65
  Dir.mktmpdir do |tmp_dir|
46
66
  tmp_dir = Pathname(tmp_dir)
@@ -49,16 +49,16 @@ module Natour
49
49
  .map { |description| Species.new(*description.scan(/&gt;([^&(]+)&lt;/).flatten.reverse) }
50
50
  .sort_by(&:name_de).uniq
51
51
  [SpeciesList.new(filename, date, :ornitho_ch, :birds, name, nil, items)]
52
- when /^Favoriten/
52
+ when /^(Favoriten|NUMMER_FLORA)/
53
53
  CSV.open(filename, 'r:bom|utf-8', col_sep: ';', skip_blanks: true) do |csv|
54
- chunks = csv.reject { |row| row.count == 1 && row[0] != 'Favoriten' }
55
- .reject { |row| row.count == 4 && row[0] == 'NUMMER_FLORA' }
54
+ chunks = csv.reject { |row| row.count == 1 }
55
+ .map { |row| row[0] == 'NUMMER_FLORA' ? ['Favoriten'] : row }
56
56
  .slice_before { |row| row.count == 1 || row.count == 3 }
57
57
  .reject { |rows| rows.count == 1 }
58
58
  chunks.map do |rows|
59
59
  name, description = rows.shift
60
60
  date = DateUtils.parse(name, Pathname(filename).basename).compact.first
61
- items = rows.map { |row| Species.new(row[1][/^(([^ ]+ [^ ]+)(( aggr\.)|( subsp\. [^ ]+))?)/, 1], row[2]) }
61
+ items = rows.map { |row| Species.new(BotanicalNameUtils.parse(row[1]), row[2]) }
62
62
  .sort_by(&:name).uniq
63
63
  SpeciesList.new(
64
64
  filename,
@@ -75,7 +75,7 @@ module Natour
75
75
  CSV.open(filename, 'r:bom|utf-16le:utf-8', col_sep: "\t", headers: true) do |csv|
76
76
  date = DateUtils.parse(Pathname(filename).basename).compact.first
77
77
  items = csv.select { |row| row[0] }
78
- .map { |row| Species.new(row[11][/^(([^ ]+ [^ ]+)(( aggr\.)|( subsp\. [^ ]+))?)/, 1], nil) }
78
+ .map { |row| Species.new(BotanicalNameUtils.parse(row[11]), nil) }
79
79
  .sort_by(&:name).uniq
80
80
  [SpeciesList.new(filename, date, :info_flora, :plants, nil, nil, items)]
81
81
  end
@@ -0,0 +1,12 @@
1
+ module Natour
2
+ module BotanicalNameUtils
3
+ module_function
4
+
5
+ def parse(name)
6
+ result = name.match(/^([^ ]+ [^ ]+)(( aggr\.)|(.*( subsp\. [^ ]+)))?.*$/)
7
+ return unless result
8
+
9
+ "#{result[1]}#{result[3]}#{result[5]}"
10
+ end
11
+ end
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: natour
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Gysi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-02 00:00:00.000000000 Z
11
+ date: 2021-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -199,6 +199,7 @@ files:
199
199
  - lib/natour/species.rb
200
200
  - lib/natour/species_list.rb
201
201
  - lib/natour/station.rb
202
+ - lib/natour/utils/botanical_name_utils.rb
202
203
  - lib/natour/utils/date_utils.rb
203
204
  - lib/natour/utils/stdout_utils.rb
204
205
  homepage: https://rubygems.org/gems/natour