Class: Capybara::UI::StringValue

Inherits:
String
  • Object
show all
Defined in:
lib/capybara/ui/widgets/string_value.rb

Defined Under Namespace

Classes: Money

Instance Method Summary collapse

Instance Method Details

#to_date(format = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/capybara/ui/widgets/string_value.rb', line 4

def to_date(format = nil)
  if format
    Date.strptime(self, format)
  elsif defined?(super)
    super()
  else
    Date.parse(self)
  end
end

#to_keyObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/capybara/ui/widgets/string_value.rb', line 14

def to_key
  fst, rest = first, self[1..-1]
  decamelized = fst + rest.gsub(/([A-Z])/, '_\1')
  underscored = decamelized.gsub(/[\W_]+/, '_')
  stripped = underscored.gsub(/^_|_$/, '')
  downcased = stripped.downcase
  key = downcased.to_sym

  key
end

#to_splitObject



46
47
48
# File 'lib/capybara/ui/widgets/string_value.rb', line 46

def to_split
  split(',').map(&:strip).map { |e| self.class.new(e) }
end

#to_usdObject



42
43
44
# File 'lib/capybara/ui/widgets/string_value.rb', line 42

def to_usd
  Money.new(self)
end