lib/watir/radio_set.rb in watir-6.13.0 vs lib/watir/radio_set.rb in watir-6.14.0
- old
+ new
@@ -2,18 +2,16 @@
class RadioSet
extend Forwardable
include Watir::Exception
include Enumerable
- delegate [:exists?, :present?, :visible?, :browser] => :source
+ delegate %i[exists? present? visible? browser] => :source
attr_reader :source, :frame
def initialize(query_scope, selector)
- unless selector.kind_of? Hash
- raise ArgumentError, "invalid argument: #{selector.inspect}"
- end
+ raise ArgumentError, "invalid argument: #{selector.inspect}" unless selector.is_a? Hash
@source = Radio.new(query_scope, selector)
@frame = @source.parent(tag_name: :form)
end
@@ -48,27 +46,26 @@
#
def radio(opt = {})
n = name
if !n.empty? && (!opt[:name] || opt[:name] == n)
- frame.radio(opt.merge name: n)
+ frame.radio(opt.merge(name: n))
elsif n.empty?
return source
else
raise Watir::Exception::UnknownObjectException, "#{opt[:name]} does not match name of RadioSet: #{n}"
end
-
end
#
# @return Watir::RadioCollection
#
def radios(opt = {})
n = name
if !n.empty? && (!opt[:name] || opt[:name] == n)
- element_call(:wait_for_present) { frame.radios(opt.merge name: n) }
+ element_call(:wait_for_present) { frame.radios(opt.merge(name: n)) }
elsif n.empty?
Watir::RadioCollection.new(frame, element: source.wd)
else
raise Watir::Exception::UnknownObjectException, "#{opt[:name]} does not match name of RadioSet: #{n}"
end
@@ -109,11 +106,11 @@
#
# @return [String]
#
def type
- source.send :assert_exists
+ assert_exists
'radio'
end
#
# Returns true if the radio set has one or more radio buttons where label matches the given value.
@@ -159,10 +156,11 @@
def selected?(str_or_rx)
found = frame.radio(label: str_or_rx)
return found.selected? if found.exist?
+
raise UnknownObjectException, "Unable to locate radio matching #{str_or_rx.inspect}"
end
#
# Returns the value of the selected radio button in the set.
@@ -171,11 +169,11 @@
# @return [String, nil]
#
def value
sel = selected
- sel && sel.value
+ sel&.value
end
#
# Returns the text of the selected radio button in the set.
# Returns nil if no option is selected.
@@ -183,11 +181,11 @@
# @return [String, nil]
#
def text
sel = selected
- sel && sel.text
+ sel&.text
end
#
# Returns the selected Radio element.
# Returns nil if no radio button is selected.
@@ -206,26 +204,27 @@
# browser.radio_set(id: 'new_user_newsletter_yes') == browser.radio_set(id: 'new_user_newsletter_no')
# #=> true
#
def ==(other)
- return false unless other.kind_of?(self.class)
+ return false unless other.is_a?(self.class)
+
radios == other.radios
end
- alias_method :eql?, :==
+ alias eql? ==
- private
-
- def element_call(*args, &blk)
- source.send :element_call, *args, &blk
+ # Ruby 2.4+ complains about using #delegate to do this
+ %i[assert_exists element_call].each do |method|
+ define_method(method) do |*args, &blk|
+ source.send(method, *args, &blk)
+ end
end
end # RadioSet
module Container
def radio_set(*args)
- RadioSet.new(self, extract_selector(args).merge(tag_name: "input", type: "radio"))
+ RadioSet.new(self, extract_selector(args).merge(tag_name: 'input', type: 'radio'))
end
Watir.tag_to_class[:radio_set] = RadioSet
end # Container
-
end # Watir