Module: Hatio::Util::HatioUtil
- Defined in:
- lib/hatio-core/util/hatio_util.rb
Overview
Simple util class
Instance Method Summary collapse
-
#check_required_param(params, name) ⇒ Object
필수 파라미터 체크.
-
#check_required_params(params, name_arr) ⇒ Object
필수 파라미터 리스트 체크.
-
#convert_date_bet_cond(date) ⇒ Object
단일 날짜를 between 으로 변경.
- #convert_date_eq_cond(date) ⇒ Object
-
#convert_time_to_db(time) ⇒ Object
time string을 db time으로 변경.
-
#debug_print(obj) ⇒ Object
for debug.
-
#empty_param?(params, name) ⇒ Boolean
parameter empty check.
-
#generateUUID ⇒ Object
UUID 생성.
-
#parse_date(date_str) ⇒ Object
server configuration에서 지정된 포맷대로 date_str을 파싱하여 date 객체를 리턴.
-
#parse_time(time_str) ⇒ Object
server configuration에서 지정된 포맷대로 date_str을 파싱하여 date 객체를 리턴.
-
#parse_time_to_db(strtime) ⇒ Object
time string을 db time으로 변경.
-
#to_std_date_str(date_str) ⇒ Object
server configuration에서 지정된 포맷대로 date_str을 파싱하여 date 객체를 리턴.
-
#to_std_time_str(time_str) ⇒ Object
server configuration에서 지정된 포맷대로 date_str을 파싱하여 date 객체를 리턴.
Instance Method Details
#check_required_param(params, name) ⇒ Object
필수 파라미터 체크
49 50 51 |
# File 'lib/hatio-core/util/hatio_util.rb', line 49 def check_required_param(params, name) raise StandardError, "Parameter #{name} is required!" if(!params.key?(name.to_s) || params[name.to_s].blank?) end |
#check_required_params(params, name_arr) ⇒ Object
필수 파라미터 리스트 체크
54 55 56 |
# File 'lib/hatio-core/util/hatio_util.rb', line 54 def check_required_params(params, name_arr) name_arr.each { |name| check_required_param(params, name) } end |
#convert_date_bet_cond(date) ⇒ Object
단일 날짜를 between 으로 변경
59 60 61 |
# File 'lib/hatio-core/util/hatio_util.rb', line 59 def convert_date_bet_cond(date) "between ? and ?" end |
#convert_date_eq_cond(date) ⇒ Object
64 65 66 |
# File 'lib/hatio-core/util/hatio_util.rb', line 64 def convert_date_eq_cond(date) "Date'#{date}'" end |
#convert_time_to_db(time) ⇒ Object
time string을 db time으로 변경
27 28 29 30 31 32 33 |
# File 'lib/hatio-core/util/hatio_util.rb', line 27 def convert_time_to_db(time) if ActiveRecord::Base.default_timezone == :utc time.to_time.utc else time.to_time.localtime end end |
#debug_print(obj) ⇒ Object
for debug
7 8 9 10 11 |
# File 'lib/hatio-core/util/hatio_util.rb', line 7 def debug_print(obj) puts "*" * 30 puts obj puts "*" * 30 end |
#empty_param?(params, name) ⇒ Boolean
parameter empty check
43 44 45 46 |
# File 'lib/hatio-core/util/hatio_util.rb', line 43 def empty_param?(params, name) name = name.to_s return (params[name].nil? || params[name].empty?) end |
#generateUUID ⇒ Object
UUID 생성
16 17 18 19 |
# File 'lib/hatio-core/util/hatio_util.rb', line 16 def generateUUID Digest::SHA1.hexdigest(Time.now.to_s.split(//).sort_by {rand}.join).to_s # UUIDTools::UUID.timestamp_create().to_s end |
#parse_date(date_str) ⇒ Object
server configuration에서 지정된 포맷대로 date_str을 파싱하여 date 객체를 리턴
71 72 73 74 75 76 77 |
# File 'lib/hatio-core/util/hatio_util.rb', line 71 def parse_date(date_str) begin return Date.strptime(date_str, GlobalConfig.date_format) rescue ::Exception => e return Date.parse(date_str) end end |
#parse_time(time_str) ⇒ Object
server configuration에서 지정된 포맷대로 date_str을 파싱하여 date 객체를 리턴
89 90 91 92 93 94 95 |
# File 'lib/hatio-core/util/hatio_util.rb', line 89 def parse_time(time_str) begin return Time.strptime(time_str, GlobalConfig.datetime_format) rescue ::Exception => e return Time.parse(time_str) end end |
#parse_time_to_db(strtime) ⇒ Object
time string을 db time으로 변경
22 23 24 |
# File 'lib/hatio-core/util/hatio_util.rb', line 22 def parse_time_to_db(strtime) convert_time_to_db Time.zone.parse(strtime) end |
#to_std_date_str(date_str) ⇒ Object
server configuration에서 지정된 포맷대로 date_str을 파싱하여 date 객체를 리턴
82 83 84 |
# File 'lib/hatio-core/util/hatio_util.rb', line 82 def to_std_date_str(date_str) return parse_date(date_str).to_s end |
#to_std_time_str(time_str) ⇒ Object
server configuration에서 지정된 포맷대로 date_str을 파싱하여 date 객체를 리턴
100 101 102 |
# File 'lib/hatio-core/util/hatio_util.rb', line 100 def to_std_time_str(time_str) return parse_time(time_str).to_s end |