Class: StudyEngine::StudyID

Inherits:
Object
  • Object
show all
Defined in:
app/models/study_engine/study_id.rb,
app/models/study_engine/study_id/bank.rb,
app/models/study_engine/study_id/sync.rb

Defined Under Namespace

Classes: Bank, Sync

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(slug = nil) ⇒ StudyID

Returns a new instance of StudyID.



18
19
20
# File 'app/models/study_engine/study_id.rb', line 18

def initialize slug=nil
  @study, @site, @id = slug.split("-") if slug
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



16
17
18
# File 'app/models/study_engine/study_id.rb', line 16

def id
  @id
end

#siteObject

Returns the value of attribute site.



16
17
18
# File 'app/models/study_engine/study_id.rb', line 16

def site
  @site
end

#studyObject

Returns the value of attribute study.



16
17
18
# File 'app/models/study_engine/study_id.rb', line 16

def study
  @study
end

Class Method Details

.dump(study_id) ⇒ Object



10
11
12
# File 'app/models/study_engine/study_id.rb', line 10

def self.dump study_id
  study_id.to_s
end

.load(slug) ⇒ Object



5
6
7
8
# File 'app/models/study_engine/study_id.rb', line 5

def self.load slug
  return unless slug
  new slug
end

Instance Method Details

#<=>(other) ⇒ Object



34
35
36
# File 'app/models/study_engine/study_id.rb', line 34

def <=> other
  to_s <=> other.to_s
end

#present?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/study_engine/study_id.rb', line 38

def present?
  [@study, @site, @id].all?(&:present?)
end

#to_sObject



30
31
32
# File 'app/models/study_engine/study_id.rb', line 30

def to_s
  [study, site, id].join("-")
end

#valid?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/study_engine/study_id.rb', line 42

def valid?
  to_s =~ %r{\A[A-Z]{3}-[A-Z]{3}-[0-9]{4}\Z}
end