Class: Scat::Configuration
- Inherits:
-
Object
- Object
- Scat::Configuration
- Defined in:
- lib/scat/configuration.rb
Overview
The Scat Configuration specifies the edit form fields.
Instance Method Summary collapse
-
#[](name_or_label) ⇒ Field
The corresponding field.
-
#fields ⇒ <Field>
Returns the edit form field specifications.
-
#initialize(file) ⇒ Configuration
constructor
A new instance of Configuration.
-
#slice(params) ⇒ {Class => {CaRuby::Property => Object}}
The caTissue class => { property => value } hash.
Constructor Details
#initialize(file) ⇒ Configuration
Returns a new instance of Configuration.
9 10 11 12 13 |
# File 'lib/scat/configuration.rb', line 9 def initialize(file) # the field name => Field hash @fld_hash = parse(YAML.load_file(file)) logger.info("Scat fields: #{@fld_hash.values.pp_s}") end |
Instance Method Details
#[](name_or_label) ⇒ Field
Returns the corresponding field.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/scat/configuration.rb', line 17 def [](name_or_label) # the standardized field name key = case name_or_label when Symbol then name_or_label when String then Field.name_for(name_or_label).to_sym else raise ArgumentError.new("Scat field argument not supported: #{name_or_label.qp}") end @fld_hash[key] end |
#fields ⇒ <Field>
Returns the edit form field specifications.
33 34 35 |
# File 'lib/scat/configuration.rb', line 33 def fields @fld_hash.values end |
#slice(params) ⇒ {Class => {CaRuby::Property => Object}}
Returns the caTissue class => { property => value } hash.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/scat/configuration.rb', line 39 def slice(params) hash = Jinx::LazyHash.new { Hash.new } params.each do |name, value| next if value.nil? # Skip the param if it is not obtained from the request. field = @fld_hash[name.to_sym] || next field.properties.each do |klass, prop| # Convert non-string values. if prop.type <= Integer or prop.type <= Java::JavaLang::Integer then value = value.to_i elsif prop.type <= Date or prop.type <= Java::JavaUtil::Date then value = DateTime.parse(value) elsif prop.type <= Numeric or prop.type <= Java::JavaLang::Number then value = value.to_f end # Generalize a Specimen subclass. klass = CaTissue::Specimen if klass < CaTissue::Specimen # Add the property value. hash[klass][prop.to_sym] = value end end hash end |