module DwcaHunter

DwcaHunter a namespace module for the project.

Constants

BATCH_SIZE
VERSION

Attributes

logger[W]
resource[R]

Public Class Methods

logger() click to toggle source
# File lib/dwca_hunter.rb, line 31
def logger
  @logger ||= Logger.new(nil)
end
logger_reset() click to toggle source
# File lib/dwca_hunter.rb, line 37
def logger_reset
  self.logger = Logger.new(nil)
end
logger_write(obj_id, message, method = :info) click to toggle source
# File lib/dwca_hunter.rb, line 41
def logger_write(obj_id, message, method = :info)
  logger.send(method, "|#{obj_id}|#{message}|")
end
move_initials(ary) click to toggle source
# File lib/dwca_hunter.rb, line 70
def move_initials(ary)
  res = []
  ary.each do |a|
    if res.empty?
      res << a
      next
    end
    match = /^([[:upper:]]{1,4})(\sJr)?$/.match(a)
    if !match.nil?
      initialls = match[1].split("").join(". ")
      res[-1] = "#{initialls}. #{res[-1]}#{match[2]}"
    else
      res << a
    end
  end
  res.size == 1 ? res[0] : "#{res[0..-2].join(', ')} & #{res[-1]}"
end
normalize_authors(auth) click to toggle source
# File lib/dwca_hunter.rb, line 57
def normalize_authors(auth)
  reg = Regexp.new(/^(\(?)(.*?)(([\s,)][^[:upper:]]*)?$)/)
  auth = auth.gsub(/duPont/, "du Pont")
  match = reg.match(auth)
  return auth if match.nil?

  a1, a2, a3 = match[1..3]
  a2mod = a2.gsub("&", ",")
  ary2 = a2mod.split(",").map(&:strip)
  a2 = move_initials(ary2) if ary2.size > 1
  "#{a1}#{a2}#{a3}"
end
process(resource) click to toggle source
# File lib/dwca_hunter.rb, line 45
def process(resource)
  resource.download if resource.needs_download?
  resource.unpack if resource.needs_unpack?
  resource.make_dwca
end
resources() click to toggle source
# File lib/dwca_hunter.rb, line 51
def resources
  ObjectSpace.each_object(Class).select do |c|
    c < Resource
  end
end
version() click to toggle source
# File lib/dwca_hunter/version.rb, line 4
def self.version
  VERSION
end