Class: Bike::Select

Inherits:
Field
  • Object
show all
Defined in:
lib/scalar/select.rb

Overview

Author

Akira FUNAI

Copyright

Copyright © 2009 Akira FUNAI

Constant Summary

Constants inherited from Field

Field::DEFAULT_META

Instance Attribute Summary

Attributes inherited from Field

#action, #result

Instance Method Summary collapse

Methods inherited from Field

#[], #[]=, #commit, #create, #default_action, #delete, #empty?, #find_ancestor, #get, h, #inspect, instance, #item, #load, #load_default, #meta_admins, #meta_client, #meta_folder, #meta_full_name, #meta_group, #meta_name, #meta_owner, #meta_owners, #meta_roles, #meta_sd, #meta_short_name, #pending?, #permit?, #post, #update, #val, #valid?, #workflow

Methods included from I18n

_, bindtextdomain, domain, domain=, find_msg, lang, lang=, merge_msg!, msg, n_, parse_msg, po_dir, po_dir=

Constructor Details

#initialize(meta = {}) ⇒ Select

Returns a new instance of Select.



8
9
10
11
12
# File 'lib/scalar/select.rb', line 8

def initialize(meta = {})
  meta[:mandatory] = meta[:tokens] && meta[:tokens].include?('mandatory')
  meta[:options] ||= meta[:max] && (meta[:min].to_i..meta[:max]).collect {|i| i.to_s }
  super
end

Instance Method Details

#errorsObject



14
15
16
17
18
19
20
21
22
# File 'lib/scalar/select.rb', line 14

def errors
  if my[:mandatory] && val.empty?
    [_('mandatory')]
  elsif my[:options].include?(val) || val.empty?
    []
  else
    [_('no such option')]
  end
end