Skip to content

Instantly share code, notes, and snippets.

@samsee
Last active April 14, 2016 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samsee/458400dfd36d93d8a2ccc2114bd3ce61 to your computer and use it in GitHub Desktop.
Save samsee/458400dfd36d93d8a2ccc2114bd3ce61 to your computer and use it in GitHub Desktop.
Array to Hash, Key is Hangul(Korean Alphabet) Jaeum.
# 루비(ruby)에서 한글 초성에 따라 필터링하기 예제.
# 한글 자모(가-힣). 정규식에서 사용
hanguls = {
ㄱ:["\uAC00", "\uB097"],
ㄴ:["\uB098", "\uB2E3"],
ㄷ:["\uB2E4", "\uB77B"],
ㄹ:["\uB77C", "\uB9C7"],
ㅁ:["\uB9C8", "\uBC13"],
ㅂ:["\uBC14", "\uC0AB"],
ㅅ:["\uC0AC", "\uC543"],
ㅇ:["\uC544", "\uC78F"],
ㅈ:["\uC790", "\uCC27"],
ㅊ:["\uCC28", "\uCE73"],
ㅋ:["\uCE74", "\uD0BF"],
ㅌ:["\uD0C0", "\uD30B"],
ㅍ:["\uD30C", "\uD557"],
ㅎ:["\uD558", "\uD7A3"]
}
# project.name 을 정규식으로 필터링해서 prj_grp 해시맵에 담기
prj_grp = {}
hanguls.map do |key,range|
prj_grp[key] = projects.select {|prj| prj if prj.name.match(/^[#{range.first}-#{range.last}]/)}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment