삽질/Ruby4 [Ruby] 빈 공간 텍스트 채우기 "hello".ljust(4) #=> "hello""hello".ljust(20) #=> "hello ""hello".ljust(20, '1234') #=> "hello123412341234123" "hello".rjust(20, '1234') #=> "123412341234123hello" 2014. 11. 28. [Ruby] Time 비교하기 time1 = Time.nowtime2 = Time.now + 120 # 2분 후 timecheck = time2 - time1 case timecheckwhen 0 then p 'just now'when 1 then p 'a second ago'when 2..59 then p timecheck.to_s + ' seconds ago' when 60..119 then p 'a minute ago' # 120 = 2 minuteswhen 120..3540 then p (timecheck/60).to_i.to_s + ' minutes ago'when 3541..7100 then p 'an hour ago' # 3600 = 1 hourwhen 7101..82800 then p ((timecheck+99)/360.. 2014. 11. 26. [Ruby] File Time File.atime('파일주소') # Returns the last access timeFile.ctime('파일주소') # Returns the change time for file File.mtime('파일주소') # Returns the modification time for file. http://ruby-doc.org/core-1.9.3/File.html 2014. 11. 26. [Ruby] html 예제 왜 자꾸 까먹지.. data = Hpricot(data) data.search('//table[@class="table_02"]')[1] data.search('//iframe[@id="arap"]').attr('src').to_s (str_line.search("td")[3]/"text()").to_s.strip.gsub(/\t|\n/, "") data_list.search("//tr").each do |str_line|# (str_line.search("td")[0]/"a"/"text()")[0].to_s# (str_line.search("td")[0]/"text()").to_s# str_line.search("//td[@class='center']")[0]end http = HTTPClient.ne.. 2014. 11. 26. 이전 1 다음