Class: Mechanize::Form
- Inherits:
-
Object
- Object
- Mechanize::Form
- Defined in:
- lib/saber/mechanize_ext.rb
Instance Method Summary collapse
-
#get(type, criteial) ⇒ Object
A Generic api to get value.
-
#set(type, criteia, value) ⇒ Object
A Generic api to set value.
Instance Method Details
#get(type, criteial) ⇒ Object
A Generic api to get value
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/saber/mechanize_ext.rb', line 4 def get(type, criteial) case type.to_sym when :text, :hidden, :textarea, :keygen (f=field(criteia)) ? f.value : nil when :radiobutton (f=(criteia)) ? f.checked? : nil when :checkbox (f=checkbox(criteia)) ? f.checked? : nil when :multi_select_list, :select_list (f=field(criteia)) ? f.value : nil when :multi_select_list_text, :select_list_text (f=field(criteia)) ? f.text_value : nil when :file_upload (f=file_upload(criteia)) ? f.file_name : nil else raise ArgumentError, "the type argument is wrong -- #{type.insepect}" end end |
#set(type, criteia, value) ⇒ Object
A Generic api to set value
types: :text, :hidden, :textarea, :keygen, :radiobutton, :checkbox,
:multi_select_list[_text] :select_list[_text] :file_upload
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/saber/mechanize_ext.rb', line 39 def set(type, criteia, value) return nil if value.nil? case type.to_sym when :text, :hidden, :textarea, :keygen (f=field(criteia)) ? f.value = value : nil when :radiobutton (f=(criteia)) ? f.check(value) : nil when :checkbox (f=checkbox(criteia)) ? f.check(value) : nil when :multi_select_list, :select_list (f=field(criteia)) ? f.value = value : nil when :multi_select_list_text, :select_list_text (f=field(criteia)) ? f.text_value = value : nil when :file_upload (f=file_upload(criteia)) ? f.file_name = value : nil else raise ArgumentError, "the type argument is wrong -- #{type.insepect}" end end |