Sha256: e517127fbee8de742f797c5f5c7df0607901de239ec746c051d41c1975f52104
Contents?: true
Size: 1.31 KB
Versions: 3
Compression:
Stored size: 1.31 KB
Contents
require "relaton_bib/version" require "relaton_bib/deep_dup" require "relaton_bib/bibliographic_item" require "relaton_bib/hit_collection" require "relaton_bib/hit" module RelatonBib class Error < StandardError; end class RequestError < StandardError; end class << self # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength # @param date [String, Integer, Date] # @return [Date, NilClass] def parse_date(date) return date if date.is_a?(Date) sdate = date.to_s case sdate when /(?<date>\w+\s\d{4})/ # February 2012 Date.strptime($~[:date], "%B %Y") when /(?<date>\w+\s\d{1,2},\s\d{4})/ # February 11, 2012 Date.strptime($~[:date], "%B %d, %Y") when /(?<date>\d{4}-\d{2}-\d{2})/ # 2012-02-11 Date.parse($~[:date]) when /(?<date>\d{4}-\d{2})/ # 2012-02 Date.strptime date, "%Y-%m" when /(?<date>\d{4})/ then Date.strptime $~[:date], "%Y" # 2012 end end # rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength end private # @param array [Array] # @return [Array<String>, String] def single_element_array(array) if array.size > 1 array.map { |e| e.is_a?(String) ? e : e.to_hash } else array.first&.is_a?(String) ? array[0] : array.first&.to_hash end end end
Version data entries
3 entries across 3 versions & 2 rubygems