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
114
115
116
|
# File 'lib/chop/form.rb', line 114
def field
@field
end
|
#label ⇒ Object
Returns the value of attribute label
114
115
116
|
# File 'lib/chop/form.rb', line 114
def label
@label
end
|
#path ⇒ Object
Returns the value of attribute path
114
115
116
|
# File 'lib/chop/form.rb', line 114
def path
@path
end
|
#session ⇒ Object
Returns the value of attribute session
114
115
116
|
# File 'lib/chop/form.rb', line 114
def session
@session
end
|
#value ⇒ Object
Returns the value of attribute value
114
115
116
|
# File 'lib/chop/form.rb', line 114
def value
@value
end
|
Class Method Details
.candidates ⇒ Object
128
129
130
131
132
|
# File 'lib/chop/form.rb', line 128
def self.candidates
descendants.sort_by do |a|
a == Chop::Form::Default ? 1 : -1 end
end
|
.combined_css_selector ⇒ Object
138
139
140
|
# File 'lib/chop/form.rb', line 138
def self.combined_css_selector
candidates.map(&:css_selector).uniq.join(", ")
end
|
.css_selector ⇒ Object
134
135
136
|
# File 'lib/chop/form.rb', line 134
def self.css_selector
"input"
end
|
.for(session, label, value, path) ⇒ Object
115
116
117
118
119
120
|
# File 'lib/chop/form.rb', line 115
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
122
123
124
125
126
|
# File 'lib/chop/form.rb', line 122
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
163
164
165
|
# File 'lib/chop/form.rb', line 163
def diff_value
get_value.to_s
end
|
#fill_in! ⇒ Object
167
168
169
|
# File 'lib/chop/form.rb', line 167
def fill_in!
field.set value
end
|
#get_value ⇒ Object
142
143
144
|
# File 'lib/chop/form.rb', line 142
def get_value
field.value
end
|
#label_text ⇒ Object
152
153
154
155
156
|
# File 'lib/chop/form.rb', line 152
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
146
147
148
149
150
|
# File 'lib/chop/form.rb', line 146
def should_include_in_diff?
field[:name].present? &&
field[:type] != "submit" &&
field[:type] != "hidden"
end
|
#to_diff_row ⇒ Object
158
159
160
161
|
# File 'lib/chop/form.rb', line 158
def to_diff_row
return nil unless label = label_text
[label, diff_value]
end
|