Module: RelatonBib

Included in:
Affiliation, BibliographicItem, BibliographicItem::Version, ContributionInfo, Contributor, ContributorRole, CopyrightAssociation, DocumentRelation, EditorialGroup, FullName, LocalityStack, LocalizedString, StructuredIdentifier, StructuredIdentifierCollection
Defined in:
lib/relaton_bib/contribution_info.rb,
lib/relaton_bib.rb,
lib/relaton_bib/hit.rb,
lib/relaton_bib/ics.rb,
lib/relaton_bib/place.rb,
lib/relaton_bib/medium.rb,
lib/relaton_bib/person.rb,
lib/relaton_bib/series.rb,
lib/relaton_bib/edition.rb,
lib/relaton_bib/version.rb,
lib/relaton_bib/forename.rb,
lib/relaton_bib/validity.rb,
lib/relaton_bib/full_name.rb,
lib/relaton_bib/typed_uri.rb,
lib/relaton_bib/workgroup.rb,
lib/relaton_bib/xml_parser.rb,
lib/relaton_bib/biblio_note.rb,
lib/relaton_bib/contributor.rb,
lib/relaton_bib/organization.rb,
lib/relaton_bib/workers_pool.rb,
lib/relaton_bib/bibtex_parser.rb,
lib/relaton_bib/bibxml_parser.rb,
lib/relaton_bib/formatted_ref.rb,
lib/relaton_bib/biblio_version.rb,
lib/relaton_bib/classification.rb,
lib/relaton_bib/hash_converter.rb,
lib/relaton_bib/hit_collection.rb,
lib/relaton_bib/document_status.rb,
lib/relaton_bib/editorial_group.rb,
lib/relaton_bib/renderer/bibxml.rb,
lib/relaton_bib/formatted_string.rb,
lib/relaton_bib/localized_string.rb,
lib/relaton_bib/bib_item_locality.rb,
lib/relaton_bib/document_relation.rb,
lib/relaton_bib/bibliographic_date.rb,
lib/relaton_bib/bibliographic_item.rb,
lib/relaton_bib/bibliographic_size.rb,
lib/relaton_bib/typed_title_string.rb,
lib/relaton_bib/document_identifier.rb,
lib/relaton_bib/technical_committee.rb,
lib/relaton_bib/copyright_association.rb,
lib/relaton_bib/structured_identifier.rb,
lib/relaton_bib/renderer/bibtex_builder.rb,
lib/relaton_bib/document_relation_collection.rb

Overview

RelatonBib module

Defined Under Namespace

Modules: BibXMLParser, PersonIdentifierType, Renderer Classes: Address, Affiliation, BibItemLocality, BiblioNote, BiblioNoteCollection, BibliographicDate, BibliographicItem, BibliographicSize, BibtexParser, Classification, Contact, ContributionInfo, Contributor, ContributorRole, CopyrightAssociation, DocRelationCollection, DocumentIdentifier, DocumentRelation, DocumentStatus, Edition, EditorialGroup, Error, Forename, FormattedRef, FormattedString, FullName, HashConverter, Hit, HitCollection, ICS, Locality, LocalityStack, LocalizedString, Medium, OrgIdentifier, Organization, Person, PersonIdentifier, Place, RequestError, Series, SourceLocality, SourceLocalityStack, StructuredIdentifier, StructuredIdentifierCollection, TechnicalCommittee, TypedTitleString, TypedTitleStringCollection, TypedUri, Validity, WorkGroup, WorkersPool, XMLParser

Constant Summary collapse

VERSION =
"1.14.9".freeze

Class Method Summary collapse

Class Method Details

.array(arr) ⇒ Array

Parameters:

  • arr (nil, Array, #is_a?)

Returns:



60
61
62
63
64
65
# File 'lib/relaton_bib.rb', line 60

def array(arr)
  return [] unless arr
  return [arr] unless arr.is_a?(Array)

  arr
end

.format_date(date, format, str, outformat = nil) ⇒ Date, String

Parse date string to Date object and format it

Parameters:

  • date (String)

    date string

  • format (String)

    format string

  • str (Boolean)

    return string if true in other case return Date

  • outformat (String, nil) (defaults to: nil)

    output format

Returns:

  • (Date, String)

    date object or formatted date string



53
54
55
56
# File 'lib/relaton_bib.rb', line 53

def format_date(date, format, str, outformat = nil)
  date = Date.strptime(date, format)
  str ? date.strftime(outformat || format) : date
end

.grammar_hashObject



86
87
88
89
90
91
# File 'lib/relaton_bib.rb', line 86

def self.grammar_hash
  gem_path = File.expand_path "..", __dir__
  grammars_path = File.join gem_path, "grammars", "*"
  grammars = Dir[grammars_path].sort.map { |gp| File.read gp }.join
  Digest::MD5.hexdigest grammars
end

.parse_date(date, str = true) ⇒ Date, ...

Returns date.

Parameters:

  • date (String, Integer, Date)

    date

  • str (Boolean) (defaults to: true)

    return string or Date

Returns:

  • (Date, String, nil)

    date



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/relaton_bib.rb', line 26

def parse_date(date, str = true) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity,Metrics/AbcSize
  return date if date.is_a?(Date)

  case date.to_s
  when /(?<date>\w+\s\d{4})/ # February 2012
    format_date $~[:date], "%B %Y", str, "%Y-%m"
  when /(?<date>\w+\s\d{1,2},\s\d{4})/ # February 11, 2012
    format_date $~[:date], "%B %d, %Y", str, "%Y-%m-%d"
  when /(?<date>\d{4}-\d{1,2}-\d{1,2})/ # 2012-02-03 or 2012-2-3
    format_date $~[:date], "%Y-%m-%d", str
  when /(?<date>\d{4}-\d{1,2})/ # 2012-02 or 2012-2
    format_date $~[:date], "%Y-%m", str
  when /(?<date>\d{4})/ # 2012
    format_date $~[:date], "%Y", str
  end
end

.parse_yaml(yaml, classes = [], symbolize_names: false) ⇒ Hash

Parse yaml content

Parameters:

  • yaml (String)

    content

  • classes (Array) (defaults to: [])

    classes to be allowed

  • symbolize_names (Boolean) (defaults to: false)

    symbolize names if true (default: false)

Returns:

  • (Hash)

    data



76
77
78
79
80
81
82
83
# File 'lib/relaton_bib.rb', line 76

def parse_yaml(yaml, classes = [], symbolize_names: false)
  # Newer versions of Psych uses the `permitted_classes:` parameter
  if YAML.method(:safe_load).parameters.map(&:last).include? :permitted_classes
    YAML.safe_load(yaml, permitted_classes: classes, symbolize_names: symbolize_names)
  else
    YAML.safe_load(yaml, classes, symbolize_names: symbolize_names)
  end
end