Class: StudyEngine::StudyID
- Inherits:
-
Object
- Object
- StudyEngine::StudyID
- 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
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#site ⇒ Object
Returns the value of attribute site.
-
#study ⇒ Object
Returns the value of attribute study.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(slug = nil) ⇒ StudyID
constructor
A new instance of StudyID.
- #present? ⇒ Boolean
- #to_s ⇒ Object
- #valid? ⇒ Boolean
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
#id ⇒ Object
Returns the value of attribute id.
16 17 18 |
# File 'app/models/study_engine/study_id.rb', line 16 def id @id end |
#site ⇒ Object
Returns the value of attribute site.
16 17 18 |
# File 'app/models/study_engine/study_id.rb', line 16 def site @site end |
#study ⇒ Object
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
38 39 40 |
# File 'app/models/study_engine/study_id.rb', line 38 def present? [@study, @site, @id].all?(&:present?) end |
#to_s ⇒ Object
30 31 32 |
# File 'app/models/study_engine/study_id.rb', line 30 def to_s [study, site, id].join("-") end |
#valid? ⇒ 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 |