class Arison::Util

Public Class Methods

get_profile(config_path, profile) click to toggle source
# File lib/arison/util.rb, line 5
def self.get_profile(config_path, profile)
  @config = YAML.load_file(config_path)
  @config[profile]
end
get_type(k, v) click to toggle source
# File lib/arison/util.rb, line 22
def self.get_type(k, v)
  if v.nil?
    %Q{string}
  elsif k =~ /^id$/i
    nil
  elsif v.class == String
    to_time_or_nil(v).nil? ? %Q{string} : %Q{datetime}
  elsif v.class == TrueClass || v.class == FalseClass
    %Q{boolean}
  elsif v.class == Fixnum
    %Q{integer}
  elsif v.class == Float
    %Q{float}
  elsif v.class == Array || v.class == Hash
    %Q{text}
  elsif v.respond_to?(:strftime)
    %Q{datetime}
  end
end
parse_json(buffer) click to toggle source
# File lib/arison/util.rb, line 10
def self.parse_json(buffer)
  begin
    data = JSON.parse(buffer)
  rescue => e
    data = []
    buffer.lines.each do |line|
      data << JSON.parse(line)
    end
  end
  data
end
to_time_or_nil(value) click to toggle source
# File lib/arison/util.rb, line 42
def self.to_time_or_nil(value)
  return nil if value.slice(0, 4) !~ /^[0-9][0-9][0-9][0-9]/
  begin
    time = value.to_time
    time.to_i >= 0 ? time : nil
  rescue => e
    nil
  end
end