Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/cff/formatters/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ def self.select_and_check_model(model, preferred_citation)
model.authors.empty? || model.title.empty? ? nil : model
end

def self.initial_from_name_part(part)
part.split('-').filter_map { |sub| sub[0]&.capitalize }.join('.-')
Comment thread
hainesr marked this conversation as resolved.
Resolved
end

def self.initials(name)
name.split.map { |part| part[0].capitalize }.join('. ')
name.split.map { |part| initial_from_name_part(part) }.join('. ')
end

def self.note_from_model(model)
Expand Down
1 change: 1 addition & 0 deletions test/files/formatted/hyphenated-names.apa
Comment thread
hainesr marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Kling, M.-U., & Picard, J.-L. (2021). Hyphenated names test [Computer software]
9 changes: 9 additions & 0 deletions test/files/formatter/hyphenated-names.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cff-version: 1.2.0
message: If you use this software, please cite it as below.
authors:
- family-names: Kling
given-names: Marc-Uwe
- family-names: Picard
given-names: Jean-Luc
title: Hyphenated names test
date-released: 2021-09-21
15 changes: 15 additions & 0 deletions test/formatters/formatter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@
require 'cff/index'

class CFFFormatterTest < Minitest::Test
def test_initial_from_name_part
assert_equal 'A', CFF::Formatters::Formatter.initial_from_name_part('Arfon')
assert_equal 'M', CFF::Formatters::Formatter.initial_from_name_part('M.')
assert_equal 'M.-U', CFF::Formatters::Formatter.initial_from_name_part('Marc-Uwe')
assert_equal 'J.-L', CFF::Formatters::Formatter.initial_from_name_part('Jean-Luc')
assert_equal 'A.-B.-C', CFF::Formatters::Formatter.initial_from_name_part('A-B-C')
end

def test_initials
assert_equal 'A. M', CFF::Formatters::Formatter.initials('Arfon M.')
assert_equal 'M.-U', CFF::Formatters::Formatter.initials('Marc-Uwe')
assert_equal 'J.-L. P', CFF::Formatters::Formatter.initials('Jean-Luc Picard')
assert_equal 'A. B. C', CFF::Formatters::Formatter.initials('Arfon B. C.')
end

def test_month_and_year_from_date
[nil, '', ' ', 'nil'].each do |date|
assert_equal(['', ''], CFF::Formatters::Formatter.month_and_year_from_date(date))
Expand Down
Loading