Class: Chop::Form::Field
- Inherits:
-
Struct
- Object
- Struct
- Chop::Form::Field
show all
- Defined in:
- lib/chop/form.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#field ⇒ Object
Returns the value of attribute field
93
94
95
|
# File 'lib/chop/form.rb', line 93
def field
@field
end
|
#label ⇒ Object
Returns the value of attribute label
93
94
95
|
# File 'lib/chop/form.rb', line 93
def label
@label
end
|
#path ⇒ Object
Returns the value of attribute path
93
94
95
|
# File 'lib/chop/form.rb', line 93
def path
@path
end
|
#session ⇒ Object
Returns the value of attribute session
93
94
95
|
# File 'lib/chop/form.rb', line 93
def session
@session
end
|
#value ⇒ Object
Returns the value of attribute value
93
94
95
|
# File 'lib/chop/form.rb', line 93
def value
@value
end
|
Class Method Details
.candidates ⇒ Object
107
108
109
110
111
|
# File 'lib/chop/form.rb', line 107
def self.candidates
descendants.sort_by do |a|
a == Chop::Form::Default ? 1 : -1
end
end
|
.combined_css_selector ⇒ Object
117
118
119
|
# File 'lib/chop/form.rb', line 117
def self.combined_css_selector
candidates.map(&:css_selector).uniq.join(", ")
end
|
.css_selector ⇒ Object
113
114
115
|
# File 'lib/chop/form.rb', line 113
def self.css_selector
"input"
end
|
.for(session, label, value, path) ⇒ Object
94
95
96
97
98
99
|
# File 'lib/chop/form.rb', line 94
def self.for session, label, value, path
field = FieldFinder.new(session, combined_css_selector).find(label)
candidates.map do |klass|
klass.new(session, label, value, path, field)
end.find(&:matches?)
end
|
.from(session, field) ⇒ Object
101
102
103
104
105
|
# File 'lib/chop/form.rb', line 101
def self.from session, field
candidates.map do |klass|
klass.new(session, nil, nil, nil, field)
end.find(&:matches?)
end
|
Instance Method Details
#diff_value ⇒ Object
142
143
144
|
# File 'lib/chop/form.rb', line 142
def diff_value
get_value.to_s
end
|
#fill_in! ⇒ Object
146
147
148
|
# File 'lib/chop/form.rb', line 146
def fill_in!
field.set value
end
|
#get_value ⇒ Object
121
122
123
|
# File 'lib/chop/form.rb', line 121
def get_value
field.value
end
|
#label_text ⇒ Object
131
132
133
134
135
|
# File 'lib/chop/form.rb', line 131
def label_text
return nil unless field[:id].present?
label_element = session.first("label[for='#{field[:id]}']", visible: :all, minimum: 0, wait: 0.1)
label_element&.text(:all)
end
|
#should_include_in_diff? ⇒ Boolean
125
126
127
128
129
|
# File 'lib/chop/form.rb', line 125
def should_include_in_diff?
field[:name].present? &&
field[:type] != "submit" &&
field[:type] != "hidden"
end
|
#to_diff_row ⇒ Object
137
138
139
140
|
# File 'lib/chop/form.rb', line 137
def to_diff_row
return nil unless label = label_text
[label, diff_value]
end
|