Module: Dill::Conversions

Included in:
TextTable
Defined in:
lib/dill/conversions.rb

Instance Method Summary collapse

Instance Method Details

#Boolean(val) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/dill/conversions.rb', line 3

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



14
15
16
17
18
# File 'lib/dill/conversions.rb', line 14

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

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

#Timeish(val) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
# File 'lib/dill/conversions.rb', line 20

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