Module: Capybara::UI::Conversions

Extended by:
Conversions
Included in:
Conversions, TextTable
Defined in:
lib/capybara/ui/conversions.rb

Instance Method Summary collapse

Instance Method Details

#Boolean(val) ⇒ Object


6
7
8
9
10
11
12
13
14
15
# File 'lib/capybara/ui/conversions.rb', line 6

def Boolean(val)
  case val
  when 'yes', 'true', true
    true
  when 'no', 'false', false, nil, ''
    false
  else
    raise ArgumentError, "can't convert #{val.inspect} to boolean"
  end
end

#List(valstr, &block) ⇒ Object


17
18
19
20
21
# File 'lib/capybara/ui/conversions.rb', line 17

def List(valstr, &block)
  vs = valstr.strip.split(/\s*,\s*/)

  block ? vs.map(&block) : vs
end

#Timeish(val) ⇒ Object

Raises:

  • (ArgumentError)

23
24
25
26
27
28
29
30
# File 'lib/capybara/ui/conversions.rb', line 23

def Timeish(val)
  raise ArgumentError, "can't convert nil to Timeish" if val.nil?

  return val if Date === val || Time === val || DateTime === val

  Chronic.parse(val) or
    raise ArgumentError, "can't parse #{val.inspect} to Timeish"
end