Class: Study::Metadata

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

Instance Method Summary collapse

Instance Method Details

#delayed_for_long_time?Boolean

Returns:

  • (Boolean)

35
36
37
# File 'app/models/study/metadata.rb', line 35

def delayed_for_long_time?
  DATA_RELEASE_DELAY_PERIODS.include?(data_release_delay_period)
end

#delayed_for_other_reasons?Boolean

Returns:

  • (Boolean)

31
32
33
# File 'app/models/study/metadata.rb', line 31

def delayed_for_other_reasons?
  data_release_delay_reason == DATA_RELEASE_DELAY_FOR_OTHER
end

#delayed_release?Boolean

Returns:

  • (Boolean)

23
24
25
# File 'app/models/study/metadata.rb', line 23

def delayed_release?
  data_release_timing == DATA_RELEASE_TIMING_DELAYED
end

#managed?Boolean

Returns:

  • (Boolean)

19
20
21
# File 'app/models/study/metadata.rb', line 19

def managed?
  data_release_strategy == DATA_RELEASE_STRATEGY_MANAGED
end

#never_release?Boolean

Returns:

  • (Boolean)

27
28
29
# File 'app/models/study/metadata.rb', line 27

def never_release?
  data_release_timing == DATA_RELEASE_TIMING_NEVER
end

#non_standard_agreement?Boolean

Returns:

  • (Boolean)

65
66
67
# File 'app/models/study/metadata.rb', line 65

def non_standard_agreement?
  data_release_standard_agreement == NO
end

#remove_x_and_autosomes?Boolean

Returns:

  • (Boolean)

15
16
17
# File 'app/models/study/metadata.rb', line 15

def remove_x_and_autosomes?
  remove_x_and_autosomes == YES
end

#sanity_check_y_separationObject


53
54
55
56
# File 'app/models/study/metadata.rb', line 53

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

#snp_child_studiesObject


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

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


99
100
101
102
103
# File 'app/models/study/metadata.rb', line 99

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)

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

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

#valid_policy_url?Boolean

Returns:

  • (Boolean)

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/models/study/metadata.rb', line 73

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