<commit_before>module StashDatacite
  class DataciteDate < ActiveRecord::Base
    self.table_name = 'dcs_dates'
    belongs_to :resource, class_name: StashDatacite.resource_class.to_s

    enum date_type: { accepted: 'accepted', available: 'available', copyrighted: 'copyrighted',
                      collected: 'collected', created: 'created', issued: 'issued',
                      submitted: 'submitted', updated: 'updated', valid_date: 'valid' }<commit_msg>DataciteDate with fully enum and helper methods date_type_friendly to work with values directly.<commit_after>module StashDatacite
  class DataciteDate < ActiveRecord::Base
    self.table_name = 'dcs_dates'
    belongs_to :resource, class_name: StashDatacite.resource_class.to_s

    # the valid method causes errors because it tries to add methods for enum and there is already valid method
    # so need to make it valid_date for symbol for rails not to error!
    DateTypes = %w(Accepted Available Collected Copyrighted Created Issued Submitted Updated Valid)

    DateTypesEnum = DateTypes.map{|i| [i.downcase.to_sym, i.downcase]}.to_h.select{|k,v| k != :valid}.merge({ :valid_date => 'valid'})
    DateTypesStrToFull = DateTypes.map{|i| [i.downcase, i]}.to_h

    enum date_type: DateTypesEnum

    # these are hacks around rails method problems.
    def date_type_friendly=(type)
      # self required here to work correctly
      self.date_type = type.to_s.downcase unless type.blank?
    end

    def date_type_friendly
      return nil if date_type.blank?
      return 'Valid' if self.date_type == 'valid_date' #exception for bad method names
      DateTypesStrToFull[date_type]
    end
{'fraction_non_alphanumeric': 0.0867992766726944, 'fraction_numerical': 0.0, 'mean_word_length': 3.9258160237388724, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5313470', 'n_tokens_mistral': 499, 'n_tokens_neox': 486, 'n_words': 149}