red_cap 0.2.0 → 0.3.0

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: 11bfb5b21985b7e369c6fe19c4f614e3759410e7
4
- data.tar.gz: 56eb406fb2f5526fa76ad774de9254d868a85f14
3
+ metadata.gz: 17f8b084c1543f1c9ebda525009e0b117e4376ca
4
+ data.tar.gz: 861b0f0b47d80da062846a58a0216c3d365b68b0
5
5
  SHA512:
6
- metadata.gz: 4ab013b120260dacb86d9db179a87082493d1c1d4084dca84352c01bb2384bfce802352c1301cb47360d0d05f4382683b55966f996207ae11410da8d345f6b7a
7
- data.tar.gz: 2f189e0490198267cf3608d1e5a140fe1ce8d42e3cf52f697a6fc7742fe00af8612552eb01d620893c6304f798a62ed889c147889b5a121b8f52a017d6dafae2
6
+ metadata.gz: 6958e11b0de0d79a1770fcddc68a5639338fc4f933b973643d57160468bd6f1c07a7870eaae68d91fd2d03629c70a627083158bd5aa38b9cc190bd248418a3a8
7
+ data.tar.gz: f19581696f6463a2daf2ccbaaf9993ea3d694999f5f20768df5724e0577c937a3a181fd65864458135ea838a6b47e236d5fc7fef4f4b1664784ff54e2e75532d
@@ -2,7 +2,7 @@ require "active_support/core_ext/object/blank"
2
2
 
3
3
  module REDCap
4
4
  class Form
5
- class Field < Struct.new(:form, :attributes, :responses)
5
+ class Field < Struct.new(:form, :attributes, :responses, :options)
6
6
  KEYS = [
7
7
  :field_name,
8
8
  :form_name,
@@ -66,7 +66,11 @@ module REDCap
66
66
 
67
67
  class Yesno < Field
68
68
  def value
69
- super == "1"
69
+ if options.has_key?(:default) && super == ""
70
+ options[:default]
71
+ else
72
+ super == "1"
73
+ end
70
74
  end
71
75
  end
72
76
 
data/lib/red_cap/form.rb CHANGED
@@ -13,20 +13,22 @@ module REDCap
13
13
  # field accessors
14
14
  def method_missing method, *args, **kwargs, &block
15
15
  key = method.to_s
16
- field_class = kwargs[:as]
16
+ options = kwargs.dup
17
+ field_class = options.delete(:as)
17
18
  if field_class.is_a?(Symbol)
18
19
  field_class = lookup_field_class(field_class.to_s)
19
20
  end
20
- if field = find_field(key, field_class)
21
+ if field = find_field(key, field_class, options)
21
22
  field.value
22
23
  else
23
24
  super
24
25
  end
25
26
  end
26
27
 
27
- def find_field key, field_class=nil
28
+ def find_field key, field_class, options
28
29
  field = fields.find { |field| field.field_name == key }
29
30
  field = field_class.new(self, field.attributes, responses) if field_class
31
+ field.options = options
30
32
  field
31
33
  end
32
34
 
@@ -1,3 +1,3 @@
1
1
  module REDCap
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: red_cap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel