natour 0.1.0 → 0.2.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: 6a465921bd4e696f168be735851b576e1ec95eca0396eb52581801a16d9c75e1
4
- data.tar.gz: 5c0fd93836e21d57752a185842c17787894b8c56d1850564240a6f88b514dcb5
3
+ metadata.gz: eb00323054987bfbb4e15631640c781d2e44f1c1a86dae3d7fafca37ecdfe0d8
4
+ data.tar.gz: 99cb9c130f9aefaecb5c68684b1e52ccd12628ae2b1d0e4e316a485a304ce761
5
5
  SHA512:
6
- metadata.gz: d39f3f80ab7bc2ee632d3458d623e8f7bb517c19b2f8c3d3fcc110c15ff8c09c646e52fb59623ca3be7c7f08877e527991c5f2774c41f1f17f4752d8b7a636ff
7
- data.tar.gz: d20556324500e26c3d428c6925f0e5ceefad9dfd790f78083e25d38fe28e27756653f5eecb5f9545b978a36a28a761dd9d257fafa8ca1ff0c75b62d9d0670308
6
+ metadata.gz: 35670a2a3872135b9cad97eac2c27af4205aaea5cf1db6b38c8757589e281061ad6b22b3469e2c4ae0c350701541fdea92170d837ed4e931445f26d2f2bb7aa7
7
+ data.tar.gz: a784e70dba0803b538a58676f143e38f93b9d252d706ae470bb91bc90caef687c86464179ae2d53d20522595af02e0aadfb1cdc7b89b60f1d36449547e7b7e92
@@ -6,6 +6,26 @@ The format is based on https://keepachangelog.com/en/1.0.0/[Keep a Changelog^],
6
6
 
7
7
  == Unreleased
8
8
 
9
+ == 0.2.0 - 2021-01-24
10
+
11
+ === Added
12
+
13
+ - Add this gem's name to the footer of the PDF output
14
+ - Support species lists from https://www.ornitho.ch/[ornitho.ch^] (KML format only)
15
+ - Classify species lists by taxonomic groups (i.e. `SpeciesList.group`)
16
+
17
+ === Changed
18
+
19
+ - Change `SpeciesList.name` to `SpeciesList.title`
20
+ - Return an empty array from `SpeciesList.load_file` if the format is unknown
21
+ - Change the format of the start time in the AsciiDoc output from _12:30_ to _12:30 Uhr_
22
+ - Change the format of the duration in the AsciiDoc output from _1h30_ to _1:30 h_
23
+
24
+ === Fixed
25
+
26
+ - Get the date from images even if the orientation tag is missing
27
+ - Fix typo in help message
28
+
9
29
  == 0.1.0 - 2020-12-04
10
30
 
11
31
  === Added
data/bin/natour CHANGED
@@ -27,9 +27,9 @@ option_parser = OptionParser.new do |opts|
27
27
  opts.separator(WordWrap.ww(
28
28
  'If PATH refers to a directory, one or more reports are created in ' \
29
29
  'AsciiDoc format. GPS tracks, images and species lists (Kosmos ' \
30
- 'Vogelführer, Flora Helvetica, Info Flora Online-Feldbuch) are ' \
31
- 'included. Images of the map section covered by the GPS tracks are also ' \
32
- 'created and included. If PATH refers to an AsciiDoc file, it is ' \
30
+ 'Vogelführer, ornitho.ch, Flora Helvetica, Info Flora Online-Feldbuch) ' \
31
+ 'are included. Images of the map section covered by the GPS tracks are ' \
32
+ 'also created and included. If PATH refers to an AsciiDoc file, it is ' \
33
33
  'converted to PDF (or any other supported format).'
34
34
  ))
35
35
  opts.separator('')
@@ -49,7 +49,7 @@ option_parser = OptionParser.new do |opts|
49
49
  end
50
50
  opts.separator('')
51
51
  opts.separator('Creation:')
52
- opts.on('--track-formats FORMATS', Array, 'GPS track formats (gpx, fit') do |value|
52
+ opts.on('--track-formats FORMATS', Array, 'GPS track formats (gpx, fit)') do |value|
53
53
  config['track-formats'] = value.map(&:to_sym)
54
54
  end
55
55
  opts.on('--[no-]map', 'Create map images') do |value|
@@ -1,7 +1,7 @@
1
- require 'natour/cli/convert'
2
- require 'natour/cli/create'
3
1
  require 'natour/helpers/date_parser'
4
2
  require 'natour/helpers/suppress_output'
3
+ require 'natour/convert'
4
+ require 'natour/create'
5
5
  require 'natour/asciinurse'
6
6
  require 'natour/config'
7
7
  require 'natour/gps_track'
@@ -51,8 +51,8 @@ module Natour
51
51
  doc << '[cols="h,3"]'
52
52
  doc << '|==='
53
53
  doc << "|Datum |#{gps_track&.date&.strftime('%d.%m.%Y')}"
54
- doc << "|Startzeit |#{gps_track&.start_point&.time&.strftime('%H:%M')}"
55
- doc << "|Dauer |#{gps_track&.duration&.strftime('%thh%M')}"
54
+ doc << "|Startzeit |#{gps_track&.start_point&.time&.strftime('%H:%M Uhr')}"
55
+ doc << "|Dauer |#{gps_track&.duration&.strftime('%th:%M h')}"
56
56
  doc << "|Strecke |#{distance.call(gps_track)}"
57
57
  doc << "|Aufstieg |#{ascent.call(gps_track)}"
58
58
  doc << "|Abstieg |#{descent.call(gps_track)}"
@@ -104,10 +104,9 @@ module Natour
104
104
  doc << ''
105
105
  species_lists.each.with_index(1) do |species_list, index|
106
106
  info = {
107
- kosmos_vogelfuehrer: birds_info,
108
- flora_helvetica: plants_info,
109
- info_flora: plants_info
110
- }[species_list.type]
107
+ birds: birds_info,
108
+ plants: plants_info
109
+ }[species_list.group]
111
110
  doc << "=== #{info.title}"
112
111
  doc << ''
113
112
  doc << '[cols="1,5,5",options=header]'
@@ -13,7 +13,11 @@ module Natour
13
13
  filename,
14
14
  backend: backend,
15
15
  safe: :unsafe,
16
- standalone: true
16
+ standalone: true,
17
+ attributes: {
18
+ 'pdf-theme' => 'natour',
19
+ 'pdf-themesdir' => "#{__dir__}/data/themes"
20
+ }
17
21
  )
18
22
 
19
23
  dir = Pathname(filename).dirname
File without changes
File without changes
@@ -0,0 +1,13 @@
1
+ ---
2
+ extends: default
3
+ footer:
4
+ recto:
5
+ left:
6
+ content: 'by natour'
7
+ right:
8
+ content: '{page-number}'
9
+ verso:
10
+ left:
11
+ content: $footer_recto_right_content
12
+ right:
13
+ content: $footer_recto_left_content
@@ -11,15 +11,11 @@ module Natour
11
11
  image = Vips::Image.new_from_file(path)
12
12
  width, height = image.size
13
13
  @portrait = width < height
14
- orientation = image.get('exif-ifd0-Orientation')
15
- @portrait = orientation[/^(\d) \(/, 1].to_i.between?(5, 8)
16
- date_time = image.get('exif-ifd0-DateTime')
17
- @date_time = Timeliness.parse(
18
- date_time[/^(.*?) \(/, 1],
19
- format: 'yyyy:mm:dd hh:nn:ss'
20
- )
21
- rescue Vips::Error => e
22
- raise unless e.to_s =~ /exif-ifd0-(Orientation|DateTime)/
14
+ get_field = ->(name) { image.get(name) if image.get_fields.include?(name) }
15
+ orientation = get_field.call('exif-ifd0-Orientation')
16
+ @portrait = orientation[/^(\d) \(/, 1].to_i.between?(5, 8) if orientation
17
+ date_time = get_field.call('exif-ifd0-DateTime')
18
+ @date_time = Timeliness.parse(date_time[/^(.*?) \(/, 1], format: 'yyyy:mm:dd hh:nn:ss') if date_time
23
19
  end
24
20
 
25
21
  def portrait?
@@ -9,7 +9,7 @@ module Natour
9
9
  class MapGeoAdmin
10
10
  def initialize(port: 0)
11
11
  @doc_root = Dir.mktmpdir
12
- FileUtils.cp_r("#{__dir__}/js", @doc_root)
12
+ FileUtils.cp_r("#{__dir__}/data/js", @doc_root)
13
13
  event = Concurrent::Event.new
14
14
  @server = WEBrick::HTTPServer.new(
15
15
  StartCallback: -> { event.set },
@@ -38,7 +38,7 @@ module Natour
38
38
  .map { |filename| Image.new(filename.to_s) }
39
39
  .sort_by { |image| [image.date_time ? 0 : 1, image.date_time, image.path] }
40
40
  species_lists =
41
- Pathname.glob('**/*.csv', File::FNM_CASEFOLD)
41
+ Pathname.glob('**/*.{csv,kml}', File::FNM_CASEFOLD)
42
42
  .map { |filename| SpeciesList.load_file(filename.to_s) }
43
43
  .flatten
44
44
  .sort_by { |species_list| [species_list.type, species_list.date ? 0 : 1, species_list.date] }
@@ -1,4 +1,5 @@
1
1
  require 'csv'
2
+ require 'nokogiri'
2
3
  require 'pathname'
3
4
 
4
5
  module Natour
@@ -6,26 +7,28 @@ module Natour
6
7
  attr_reader :path
7
8
  attr_reader :date
8
9
  attr_reader :type
9
- attr_reader :name
10
+ attr_reader :group
11
+ attr_reader :title
10
12
  attr_reader :description
11
13
 
12
- def initialize(path, date, type, name, description, items)
14
+ def initialize(path, date, type, group, title, description, items)
13
15
  @path = path
14
16
  @date = date
15
17
  @type = type
16
- @name = name
18
+ @group = group
19
+ @title = title
17
20
  @description = description
18
21
  @items = items
19
22
  end
20
23
 
21
24
  def self.load_file(filename)
22
- block = IO.binread(filename, 32)
25
+ block = IO.binread(filename, 128)
23
26
  header = if block.unpack('CC') == [0xff, 0xfe]
24
27
  block[2..-1].force_encoding('utf-16le').encode('utf-8')
25
28
  elsif block.unpack('CCC') == [0xef, 0xbb, 0xbf]
26
29
  block[3..-1].force_encoding('utf-8')
27
30
  else
28
- block.force_encoding('utf-8')
31
+ block
29
32
  end
30
33
 
31
34
  case header
@@ -34,8 +37,18 @@ module Natour
34
37
  date = DateParser.parse(Pathname(filename).basename).compact.first
35
38
  items = csv.map { |row| Species.new(row[1], row[0]) }
36
39
  .sort_by(&:name_de).uniq
37
- [SpeciesList.new(filename, date, :kosmos_vogelfuehrer, nil, nil, items)]
40
+ [SpeciesList.new(filename, date, :kosmos_vogelfuehrer, :birds, nil, nil, items)]
38
41
  end
42
+ when /^<\?xml.*?www\.ornitho\.ch/m
43
+ date = DateParser.parse(Pathname(filename).basename).compact.first
44
+ doc = Nokogiri.XML(File.read(filename, mode: 'r:utf-8'))
45
+ folder = doc.at('/xmlns:kml/xmlns:Document/xmlns:Folder/xmlns:Folder/xmlns:Folder')
46
+ name = folder.at('./xmlns:name').text
47
+ items = folder.xpath('./xmlns:Placemark/xmlns:description')
48
+ .map(&:text)
49
+ .map { |description| Species.new(*description.scan(/&gt;([^&(]+)&lt;/).flatten.reverse) }
50
+ .sort_by(&:name_de).uniq
51
+ [SpeciesList.new(filename, date, :ornitho_ch, :birds, name, nil, items)]
39
52
  when /^Favoriten/
40
53
  CSV.open(filename, 'r:bom|utf-8', col_sep: ';', skip_blanks: true) do |csv|
41
54
  chunks = csv.reject { |row| row.count == 1 && row[0] != 'Favoriten' }
@@ -51,6 +64,7 @@ module Natour
51
64
  filename,
52
65
  date,
53
66
  :flora_helvetica,
67
+ :plants,
54
68
  name&.gsub(/^(\d{4}-)?\d{2}-\d{2}( |_|-)?/, ''),
55
69
  description,
56
70
  items
@@ -63,8 +77,10 @@ module Natour
63
77
  items = csv.select { |row| row[0] }
64
78
  .map { |row| Species.new(row[11][/^(([^ ]+ [^ ]+)(( aggr\.)|( subsp\. [^ ]+))?)/, 1], nil) }
65
79
  .sort_by(&:name).uniq
66
- [SpeciesList.new(filename, date, :info_flora, nil, nil, items)]
80
+ [SpeciesList.new(filename, date, :info_flora, :plants, nil, nil, items)]
67
81
  end
82
+ else
83
+ []
68
84
  end
69
85
  end
70
86
 
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.1.0
4
+ version: 0.2.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: 2020-12-04 00:00:00.000000000 Z
11
+ date: 2021-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -177,9 +177,13 @@ files:
177
177
  - bin/natour
178
178
  - lib/natour.rb
179
179
  - lib/natour/asciinurse.rb
180
- - lib/natour/cli/convert.rb
181
- - lib/natour/cli/create.rb
182
180
  - lib/natour/config.rb
181
+ - lib/natour/convert.rb
182
+ - lib/natour/create.rb
183
+ - lib/natour/data/js/bootstrap.min.js
184
+ - lib/natour/data/js/jquery-3.5.1.slim.min.js
185
+ - lib/natour/data/js/loader.js
186
+ - lib/natour/data/themes/natour-theme.yml
183
187
  - lib/natour/fit_file.rb
184
188
  - lib/natour/gps_track.rb
185
189
  - lib/natour/gps_track_point.rb
@@ -187,9 +191,6 @@ files:
187
191
  - lib/natour/helpers/date_parser.rb
188
192
  - lib/natour/helpers/suppress_output.rb
189
193
  - lib/natour/image.rb
190
- - lib/natour/js/bootstrap.min.js
191
- - lib/natour/js/jquery-3.5.1.slim.min.js
192
- - lib/natour/js/loader.js
193
194
  - lib/natour/map_geo_admin.rb
194
195
  - lib/natour/public_transport.rb
195
196
  - lib/natour/report.rb