Class: Olelo::Attributes::Attribute::Enum Private
- Inherits:
-
Olelo::Attributes::Attribute
- Object
- Olelo::Attributes::Attribute
- Olelo::Attributes::Attribute::Enum
- Defined in:
- lib/olelo/attributes.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Olelo::Attributes::Attribute
Instance Method Summary collapse
- #field_tag(attr) ⇒ Object private
-
#initialize(parent, name, values = {}) ⇒ Enum
constructor
private
A new instance of Enum.
- #parse(params) ⇒ Object private
Methods inherited from Olelo::Attributes::Attribute
#build_form, #label, #label_tag
Methods included from Util
#check, #decode64, #deep_copy, #encode64, #escape, #escape_html, #escape_javascript, included, #md5, #no_cache?, #sha256, #titlecase, #truncate, #unescape, #unescape_backslash, #unescape_html, #valid_xml_chars?, #yaml_dump, #yaml_load, #yaml_load_file
Constructor Details
#initialize(parent, name, values = {}) ⇒ Enum
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Enum.
84 85 86 87 88 |
# File 'lib/olelo/attributes.rb', line 84 def initialize(parent, name, values = {}) super(parent, name) raise 'Values must be Proc, Hash or Array' unless Proc === values || Hash === values || Array === values @values = values end |
Instance Method Details
#field_tag(attr) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/olelo/attributes.rb', line 90 def field_tag(attr) html = %{<select class="observe" id="#{key}" name="#{key}"> <option#{values.any? {|value,label| attr == value} ? '' : ' selected="selected"'}></option>} values.sort_by(&:last).each do |value,label| value_attr = value == label ? '' : %{ value="#{escape_html value}"} selected_attr = attr == value ? ' selected="selected"' : '' html << %{<option#{value_attr}#{selected_attr}>#{escape_html label}</option>} end html << '</select>' end |
#parse(params) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
101 102 103 104 |
# File 'lib/olelo/attributes.rb', line 101 def parse(params) value = params[key] value if values.include?(value) end |