Sha256: 6785d457a79b7bbdfe5db004fa0e9e870e4ee4baf77dbbadab41af627f865425

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

require 'time'
require 'chronic'

module Genability
  class Client
    # @private
    module Helpers

      private

      def pagination_params(options)
        {
          'pageStart' => options['pageStart'] || options[:page_start] || options[:page],
          'pageCount' => options['pageCount'] || options[:page_count] || options[:per_page],
        }.delete_if{ |k,v| v.nil? }
      end

      def convert_to_boolean(value = nil)
        return nil if value.nil? || value.empty?
        "true"
      end

      def multi_option_handler(value)
        return nil if value.nil?
        if value.is_a?(Array)
          value.collect{|x| x.upcase}.join(',')
        else
          value.upcase
        end
      end

      def format_to_iso8601(date_time = nil)
        if date_time.respond_to?(:iso8601)
          genability_iso8601_converter(date_time)
        else
          parse_and_format_to_iso8601(date_time)
        end
      end

      def parse_and_format_to_iso8601(date_time = nil)
        parsed_date = Chronic.parse(date_time.to_s)
        parsed_date = parsed_date.nil? ? Time.parse(date_time.to_s) : parsed_date
        genability_iso8601_converter(parsed_date)
      rescue
        nil
      end

      def genability_iso8601_converter(date_time = nil)
        date_time.iso8601(1).gsub(/(?<=\-\d{2}):(?=\d{2})/, '')
      rescue
        nil
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
genability-0.1.0 lib/genability/client/helpers.rb