<commit_before># basing this structure on that suggested in http://vrybas.github.io/blog/2014/08/15/a-way-to-organize-poros-in-rails/

# also
# monkeypatch true and false to_i to be 0 and 1
class FalseClass
  def to_i
    0
  end
end
class TrueClass
  def to_i
    1
  end
end

module StashDatacite
  module Resource
    class Completions
      def initialize(resource)
        @resource = resource
      end

      # these are the required ones and return true/false if completed
      def title
        @resource.titles.where.not(title: [nil, '']).count > 0
      end

      def institution
        @resource.creators.where.not(affiliation_id: nil).count > 0
      end

      def data_type
        !@resource.resource_type.nil?
      end

      def creator
        num_creators = @resource.creators.count
        return false if num_creators < 1
        @resource.creators.filled.count == num_creators  # the completely filled in creators must equal number of creators
      end

      def abstract
        @resource.descriptions.where(description_type: 'abstract').where.not(description: [nil, '']).count > 0
      end

      def required_completed
        title.to_i + institution.to_i + data_type.to_i + creator.to_i + abstract.to_i
      end

      def required_total
        5
      end
<commit_msg>Fixing affiliation checking for required field for author.<commit_after># basing this structure on that suggested in http://vrybas.github.io/blog/2014/08/15/a-way-to-organize-poros-in-rails/

# also
# monkeypatch true and false to_i to be 0 and 1
class FalseClass
  def to_i
    0
  end
end
class TrueClass
  def to_i
    1
  end
end

module StashDatacite
  module Resource
    class Completions
      def initialize(resource)
        @resource = resource
      end

      # these are the required ones and return true/false if completed
      def title
        @resource.titles.where.not(title: [nil, '']).count > 0
      end

      def institution
        @resource.creators.joins(:affiliations).count > 0
      end

      def data_type
        !@resource.resource_type.nil?
      end

      def creator
        num_creators = @resource.creators.count
        return false if num_creators < 1
        @resource.creators.filled.count == num_creators  # the completely filled in creators must equal number of creators
      end

      def abstract
        @resource.descriptions.where(description_type: 'abstract').where.not(description: [nil, '']).count > 0
      end

      def required_completed
        title.to_i + institution.to_i + data_type.to_i + creator.to_i + abstract.to_i
      end

      def required_total
        5
      end

{'fraction_non_alphanumeric': 0.07404608991310918, 'fraction_numerical': 0.012844729882886286, 'mean_word_length': 2.407979407979408, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3131675', 'n_tokens_mistral': 832, 'n_tokens_neox': 778, 'n_words': 234}