bsi-pipeline 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0fa6863806c23dccbf29d3a2084e673d53d1a666
4
- data.tar.gz: d2cb13ddf0cafa07bfa4b5a91b9f7b9395e7e9b5
3
+ metadata.gz: 1860307f4df0faa88344a07c7a67f1d8ea0f1f72
4
+ data.tar.gz: 8110bd05377d002f3e98ca08dc76145314ea45db
5
5
  SHA512:
6
- metadata.gz: 1221f0e7c45e2ea7e97995f4943e9b133ee5786e2d905ba3ca90cf30061806c95f699a67bfdbd379651bba86830e85961c453bd2f4b644525ca4fef8872e120e
7
- data.tar.gz: e9d4a21396e09d1ff348da06cb0ef44c02c826047f13ca4cee6f6a1b95900d5058631593ec5d9f0969f81cec2a5414082402f4919b218a714a83499b4c190128
6
+ metadata.gz: 7263ac1a8020b32bf45686a778d133bed804769a925f30387671666406710ed227405837e29b36a0c3963f3fb4da0f2f24dcd53d7f40ab482840ba5047796aa8
7
+ data.tar.gz: 03398a38f92a438a7d89c39882c6bcdbcbd23252c366238380be4705c0029cec09712191d886d97e7067922953d6321cedfdb63eac20c10ad41c6abddacb3e3d
@@ -5,9 +5,10 @@ module Pipeline
5
5
  module BSI
6
6
  module Models
7
7
  class Specimen < Pipeline::Model::Base
8
- attr_accessor :seminal_parent
9
- REQUIRED_ATTRIBUTES = %w(study_id subject_id specimen_type date_drawn date_received label_status billing_method thaws).map{|v| v.to_sym}
10
- BFH_MAP = {
8
+ attr_accessor :seminal_parent, :bfh_map
9
+
10
+ REQUIRED_FIELDS = %w(study_id subject_id specimen_type date_drawn date_received label_status billing_method thaws).map{|v| v.to_sym}
11
+ BSI_CORE_FIELDS = {
11
12
  :study_id => 'vial.study_id',
12
13
  :specimen_type => 'vial.mat_type',
13
14
  :current_label => 'vial.current_label',
@@ -45,32 +46,46 @@ module Pipeline
45
46
  :sample_modifiers => 'sample.sample_modifiers'
46
47
  }
47
48
 
48
- vial_props = (BFH_MAP.keys+REQUIRED_ATTRIBUTES).uniq
49
- begin
50
- vial_props = YAML::load(File.open(File.join(File.dirname(__FILE__), 'vial_props.yaml'))).map{|v| v.to_sym}
51
- rescue Errno::ENOENT
52
- end
53
-
54
- (vial_props-BFH_MAP.keys+[:specimen_code]).each{|attr_string| attr_accessor attr_string.to_sym}
55
- BFH_MAP.keys.each{ |attr| attr_accessor attr }
56
-
57
49
  # Define Defaults
58
- def initialize(bfh={})
50
+ def initialize(options={})
51
+ @bfh_map = Hash.new
52
+ add_attributes(BSI_CORE_FIELDS)
53
+ add_attributes(REQUIRED_FIELDS)
54
+ add_attributes(options[:custom_required_fields]) if options[:custom_required_fields]
55
+ add_attributes(options[:custom_fields]) if options[:custom_fields]
56
+ self.thaws = '0'
57
+ end
59
58
 
60
- unless bfh.empty?
61
- self.seminal_parent = true
62
- bfh.keys.each do |bfh_key|
63
- if BFH_MAP.has_value?(bfh_key)
64
- instance_eval("self.#{BFH_MAP.key(bfh_key)} = '#{bfh[bfh_key]}'")
65
- else
66
- instance_eval("self.#{bfh_key.gsub(/vial\./, '')} = '#{bfh[bfh_key]}'")
67
- end
59
+ def add_attributes(attributes)
60
+ new_attributes = Hash.new
61
+ case attributes.class.to_s
62
+ when Hash.to_s
63
+ attributes.each do |k,v|
64
+ new_attributes[k.to_sym] = v.to_s
65
+ end
66
+ when Array.to_s
67
+ attributes.each do |elem|
68
+ new_attributes[elem.to_sym] = "vial.#{elem}"
68
69
  end
69
-
70
70
  else
71
- self.thaws = '0'
71
+ raise 'Please pass either an Array or Hash of attributes'
72
+ end
73
+ (new_attributes.keys - bfh_map.keys).each do |attr|
74
+ self.class.send(:attr_accessor, attr)
72
75
  end
76
+ self.bfh_map.merge(new_attributes)
77
+ self
78
+ end
73
79
 
80
+ def build(bfh={})
81
+ self.seminal_parent = true
82
+ bfh.keys.each do |bfh_key|
83
+ if BFH_MAP.has_value?(bfh_key)
84
+ instance_eval("self.#{BFH_MAP.key(bfh_key)} = '#{bfh[bfh_key]}'")
85
+ else
86
+ instance_eval("self.#{bfh_key.gsub(/vial\./, '')} = '#{bfh[bfh_key]}'")
87
+ end
88
+ end
74
89
  end
75
90
 
76
91
  def bsi_id()
@@ -85,8 +100,8 @@ module Pipeline
85
100
  bfh = Hash.new
86
101
  # Add 1-1 matches/translations
87
102
  formatted_attributes.each do |k,v|
88
- if BFH_MAP.has_key?(k)
89
- bfh[BFH_MAP[k]] = v
103
+ if bfh_map.has_key?(k)
104
+ bfh[bfh_map[k]] = v
90
105
  else
91
106
  bfh["vial.#{k}"] = v
92
107
  end
@@ -95,11 +110,11 @@ module Pipeline
95
110
  end
96
111
 
97
112
  def valid?
98
- incomplete_attrs = REQUIRED_ATTRIBUTES.find{|v| send(v).nil?}.nil?
113
+ incomplete_attrs = REQUIRED_FIELDS.find{|v| send(v).nil?}.nil?
99
114
  end
100
115
 
101
116
  def missing_attrs
102
- REQUIRED_ATTRIBUTES.find_all{|a| send(a).nil?}
117
+ REQUIRED_FIELDS.find_all{|a| send(a).nil?}
103
118
  end
104
119
  end # class Specimen < Pipeline::Model::Base
105
120
 
@@ -1,5 +1,5 @@
1
1
  module Bsi
2
2
  module Pipeline
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
data/spec/models_spec.rb CHANGED
@@ -5,4 +5,14 @@ describe Specimen do
5
5
  @specimen = build(:specimen)
6
6
  end
7
7
 
8
+ describe '#new' do
9
+ it 'returns a new specimen object'
10
+ context 'when passed :custom_field => Hash' do
11
+ it 'adds fields and updates bfh_map' do
12
+ expect(@specimen.add_attributes({:stain_type => 'vial.field_268'})).to respond_to(:stain_type, :stain_type=)
13
+ end
14
+ end
15
+
16
+ end
17
+
8
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bsi-pipeline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elijah Christensen