Module: Opencellid

Defined in:
lib/opencellid/opencellid.rb,
lib/opencellid/bbox.rb,
lib/opencellid/cell.rb,
lib/opencellid/error.rb,
lib/opencellid/utils.rb,
lib/opencellid/measure.rb,
lib/opencellid/version.rb,
lib/opencellid/response.rb

Overview

The module for the opencellid-client gem

Defined Under Namespace

Classes: BBox, Cell, Error, Measure, Opencellid, Response

Constant Summary collapse

VERSION =

This library current version

'0.1.2'

Class Method Summary collapse

Class Method Details

.to_datetime_or_nil(string, format) ⇒ DateTime

A helper function that avoids invoking ‘strptime` on a string when it is null or empty

Parameters:

  • string (String)

    the nullable string containing the data to transformed into a DateTime

  • format (String)

    the format string as specified by ‘strptime`

Returns:

  • (DateTime)

    ‘nil` if the string passed is nil or empty, the result of `DateTime.strptime` otherwise



21
22
23
# File 'lib/opencellid/utils.rb', line 21

def self.to_datetime_or_nil(string, format)
  string and string.length > 0 ? DateTime.strptime(string, format) : nil
end

.to_f_or_nil(string) ⇒ Float

A helper function that avoids invoking ‘to_f` on a string when it is null or empty

Parameters:

  • string (String)

    the nullable string containing the data to transformed into a float

Returns:

  • (Float)

    ‘nil` if the string passed is nil or empty, the result of `to_f` otherwise



13
14
15
# File 'lib/opencellid/utils.rb', line 13

def self.to_f_or_nil(string)
  string and string.length > 0 ? string.to_f : nil
end

.to_i_or_nil(string) ⇒ Integer

A helper function that avoids invoking ‘to_i` on a string when it is null or empty

Parameters:

  • string (String)

    the nullable string containing the data to transformed into an integer

Returns:

  • (Integer)

    ‘nil` if the string passed is nil or empty, the result of `to_i` otherwise



6
7
8
# File 'lib/opencellid/utils.rb', line 6

def self.to_i_or_nil(string)
  string and string.length > 0 ? string.to_i : nil
end