Module: Rubicure::Concerns::Util

Included in:
Rubicure::Core, Movie, Series, Series
Defined in:
lib/rubicure/concerns/util.rb

Overview

utility methods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load_yaml_file(yaml_file) ⇒ Hash

Parameters:

  • yaml_file (String)

Returns:

  • (Hash)


30
31
32
# File 'lib/rubicure/concerns/util.rb', line 30

def load_yaml_file(yaml_file)
  YAML.safe_load(File.read(yaml_file), permitted_classes: [Date], aliases: true)
end

Instance Method Details

#to_date(arg) ⇒ Date?

Parameters:

  • arg (Date, Time, String)

Returns:

  • (Date)

    arg is String, Date or Time

  • (nil)

    arg is other



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rubicure/concerns/util.rb', line 9

def to_date(arg)
  case arg
  when Date
    arg
  when Time
    arg.to_date
  when String
    begin
      Date.parse(arg)
    rescue
      nil
    end
  else
    nil
  end
end