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/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/document_relation_collection.rb

Overview

RelatonBib module

Defined Under Namespace

Modules: BibXMLParser, PersonIdentifierType 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.0".freeze

Class Method Summary collapse

Class Method Details

.array(arr) ⇒ Array

Parameters:

  • arr (NilClass, Array, #is_a?)

Returns:



58
59
60
61
62
63
# File 'lib/relaton_bib.rb', line 58

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



51
52
53
54
# File 'lib/relaton_bib.rb', line 51

def format_date(date, format, str, outformat = nil)
  date = Date.strptime(date, format)
  str ? date.strftime(outformat || format) : date
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



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

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 = []) ⇒ Hash

Parse yaml content

Parameters:

  • yaml (String)

    content

Returns:

  • (Hash)

    data



72
73
74
75
76
77
78
79
# File 'lib/relaton_bib.rb', line 72

def parse_yaml(yaml, classes = [])
  # 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)
  else
    YAML.safe_load(yaml, classes)
  end
end