Class: RelatonBib::ContributorRole
- Includes:
- RelatonBib
- Defined in:
- lib/relaton_bib/contribution_info.rb
Overview
Contributor’s role.
Constant Summary collapse
- TYPES =
%w[author performer publisher editor adapter translator distributor realizer owner authorizer enabler subject].freeze
Constants included from RelatonBib
Instance Attribute Summary collapse
- #description ⇒ Array<RelatonBib::FormattedString> readonly
- #type ⇒ Strig readonly
Instance Method Summary collapse
-
#initialize(**args) ⇒ ContributorRole
constructor
A new instance of ContributorRole.
-
#to_asciibib(prefix = "", count = 1) ⇒ Object
2return [String].
- #to_hash ⇒ Hash, String
- #to_xml(**opts) ⇒ Object
Methods included from RelatonBib
array, format_date, grammar_hash, parse_date, parse_yaml
Methods included from Config
Constructor Details
#initialize(**args) ⇒ ContributorRole
Returns a new instance of ContributorRole.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/relaton_bib/contribution_info.rb', line 23 def initialize(**args) if args[:type] && !TYPES.include?(args[:type]) Util.warn %{WARNING: Contributor's type `#{args[:type]}` is invalid.} end @type = args[:type] @description = args.fetch(:description, []).map do |d| FormattedString.new content: d, format: nil end end |
Instance Attribute Details
#description ⇒ Array<RelatonBib::FormattedString> (readonly)
15 16 17 |
# File 'lib/relaton_bib/contribution_info.rb', line 15 def description @description end |
#type ⇒ Strig (readonly)
18 19 20 |
# File 'lib/relaton_bib/contribution_info.rb', line 18 def type @type end |
Instance Method Details
#to_asciibib(prefix = "", count = 1) ⇒ Object
2return [String]
58 59 60 61 62 63 64 65 66 |
# File 'lib/relaton_bib/contribution_info.rb', line 58 def to_asciibib(prefix = "", count = 1) pref = prefix.empty? ? prefix : "#{prefix}." out = count > 1 ? "#{prefix}.role::\n" : "" description.each do |d| out += d.to_asciibib "#{pref}role.description", description.size end out += "#{pref}role.type:: #{type}\n" if type out end |
#to_hash ⇒ Hash, String
48 49 50 51 52 53 |
# File 'lib/relaton_bib/contribution_info.rb', line 48 def to_hash hash = {} hash["description"] = description.map(&:to_hash) if description&.any? hash["type"] = type if type hash end |
#to_xml(**opts) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/relaton_bib/contribution_info.rb', line 37 def to_xml(**opts) # rubocop:disable Metrics/AbcSize opts[:builder].role(type: type) do |builder| desc = description.select { |d| d.language&.include? opts[:lang] } desc = description unless desc.any? desc.each do |d| builder.description { |b| d.to_xml(b) } end end end |