Class: Study::Metadata

Inherits:
Object
  • Object
show all
Defined in:
app/models/study/metadata.rb

Overview

rubocop:todo Style/Documentation

Instance Method Summary collapse

Instance Method Details

#delayed_for_long_time?Boolean

Returns:

  • (Boolean)

37
38
39
# File 'app/models/study/metadata.rb', line 37

def delayed_for_long_time?
  DATA_RELEASE_DELAY_PERIODS.include?(data_release_delay_period)
end

#delayed_for_other_reasons?Boolean

Returns:

  • (Boolean)

33
34
35
# File 'app/models/study/metadata.rb', line 33

def delayed_for_other_reasons?
  data_release_delay_reason == DATA_RELEASE_DELAY_FOR_OTHER
end

#delayed_release?Boolean

Returns:

  • (Boolean)

25
26
27
# File 'app/models/study/metadata.rb', line 25

def delayed_release?
  data_release_timing == DATA_RELEASE_TIMING_DELAYED
end

#managed?Boolean

Returns:

  • (Boolean)

21
22
23
# File 'app/models/study/metadata.rb', line 21

def managed?
  data_release_strategy == DATA_RELEASE_STRATEGY_MANAGED
end

#never_release?Boolean

Returns:

  • (Boolean)

29
30
31
# File 'app/models/study/metadata.rb', line 29

def never_release?
  data_release_timing == DATA_RELEASE_TIMING_NEVER
end

#non_standard_agreement?Boolean

Returns:

  • (Boolean)

70
71
72
# File 'app/models/study/metadata.rb', line 70

def non_standard_agreement?
  data_release_standard_agreement == NO
end

#remove_x_and_autosomes?Boolean

Returns:

  • (Boolean)

17
18
19
# File 'app/models/study/metadata.rb', line 17

def remove_x_and_autosomes?
  remove_x_and_autosomes == YES
end

#sanity_check_y_separationObject


55
56
57
58
59
60
61
# File 'app/models/study/metadata.rb', line 55

def sanity_check_y_separation
  if remove_x_and_autosomes?
    errors.add(:separate_y_chromosome_data,
               'cannot be selected with remove x and autosomes.')
  end
  !remove_x_and_autosomes?
end

#snp_child_studiesObject


111
112
113
114
115
# File 'app/models/study/metadata.rb', line 111

def snp_child_studies
  return nil if snp_study_id.nil?

  self.class.where(snp_parent_study_id: snp_study_id).includes(:study).map(&:study)
end

#snp_parent_studyObject


105
106
107
108
109
# File 'app/models/study/metadata.rb', line 105

def snp_parent_study
  return nil if snp_parent_study_id.nil?

  self.class.where(snp_study_id: snp_parent_study_id).includes(:study).try(:study)
end

#study_type_valid?Boolean

Returns:

  • (Boolean)

74
75
76
# File 'app/models/study/metadata.rb', line 74

def study_type_valid?
  errors.add(:study_type, 'is not specified') if study_type.name == 'Not specified'
end

#valid_policy_url?Boolean

Returns:

  • (Boolean)

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/study/metadata.rb', line 78

def valid_policy_url?
  # Rails 2.3 has no inbuilt URL validation, but rather than rolling our own, we'll
  # use the inbuilt ruby URI parser, a bit like here:
  # http://www.simonecarletti.com/blog/2009/04/validating-the-format-of-an-url-with-rails/
  return true if dac_policy.blank?

  dac_policy.insert(0, 'http://') unless dac_policy.include?('://') # Add an http protocol if no protocol is defined
  begin
    uri = URI.parse(dac_policy)
    if configatron.invalid_policy_url_domains.include?(uri.host)
      errors.add(:dac_policy,
                 ": #{dac_policy} is not an acceptable URL. Please ensure you haven't provided an internal URL.")
    end
  rescue URI::InvalidURIError
    errors.add(:dac_policy, ": #{dac_policy} is not a valid URL")
  end
end