Class: Arison::Util
- Inherits:
-
Object
- Object
- Arison::Util
- Defined in:
- lib/arison/util.rb
Class Method Summary collapse
- .get_profile(config_path, profile) ⇒ Object
- .get_type(k, v) ⇒ Object
- .parse_json(buffer) ⇒ Object
- .to_time_or_nil(value) ⇒ Object
Class Method Details
.get_profile(config_path, profile) ⇒ Object
5 6 7 8 |
# 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) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# 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) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# 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 |