Last active
December 16, 2015 18:39
-
-
Save gmanley/5479094 to your computer and use it in GitHub Desktop.
Ruby code snippets from my work in progress media file parser/renamer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
year = /(?<year>(20)?(07|08|09|10|11|12|13))/ | |
month = /(?<month>0[1-9]|1[012])/ | |
day = /(?<day>0[1-9]|\.[1-9]|[12][0-9]|3[01])/ | |
NUMERAL_DATE_REGEX = /#{year}(?<separator>\.|\-|\/|_)?#{month}(\k<separator>)?#{day}/ | |
NUMERAL_DATE_FORMAT = '[%y.%m.%d]' | |
# ... | |
def parse_numeral_date | |
if match = NUMERAL_DATE_REGEX.match(file_name) | |
# TODO: Need to refactor this... too many assumptions about year | |
year = match[:year].length == 2 ? '20' + match[:year] : match[:year] | |
date = Date.civil(year.to_i, match[:month].to_i, match[:day].to_i) | |
replacements[match.to_s] = date.strftime(NUMERAL_DATE_FORMAT) | |
end | |
end | |
# ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HANGUL_DATE_REGEX = /\[(\p{Hangul}+)\.(\p{Hangul}+)\.(\p{Hangul}+)\]/ | |
HANGUL_DATE_MAP = YAML.load_file(File.expand_path('../renamer/data/hangul_dates.yml', __FILE__)) | |
# ... | |
def parse_hangul_date | |
if match = HANGUL_DATE_REGEX.match(file_name) | |
original_date, hangul_year, hangul_month, hangul_day = match.to_a | |
date = Date.civil( | |
HANGUL_DATE_TO_NUMERAL['year'][hangul_year], | |
HANGUL_DATE_TO_NUMERAL['month'][hangul_month], | |
HANGUL_DATE_TO_NUMERAL['day'][hangul_day] | |
) | |
replacements[match.to_s] = date.strftime(NUMERAL_DATE_FORMAT) | |
end | |
end | |
# ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
year: | |
이천년: '2000' | |
이천일년: '2001' | |
이천이년: '2002' | |
이천삼년: '2003' | |
이천사년: '2004' | |
이천오년: '2005' | |
이천육년: '2006' | |
이천칠년: '2007' | |
이천팔년: '2008' | |
이천구년: '2009' | |
이천십년: '2010' | |
이천십일년: '2011' | |
이천십이년: '2012' | |
이천십삼년: '2013' | |
month: | |
일월: '01' | |
이월: '02' | |
삼월: '03' | |
사월: '04' | |
오월: '05' | |
유월: '06' | |
칠월: '07' | |
팔월: '08' | |
구월: '09' | |
시월: '10' | |
십일월: '11' | |
십이월: '12' | |
day: | |
일일: '01' | |
이일: '02' | |
삼일: '03' | |
사일: '04' | |
오일: '05' | |
육일: '06' | |
칠일: '07' | |
팔일: '08' | |
구일: '09' | |
십일: '10' | |
십일일: '11' | |
십이일: '12' | |
십삼일: '13' | |
십사일: '14' | |
십오일: '15' | |
십육일: '16' | |
십칠일: '17' | |
십팔일: '18' | |
십구일: '19' | |
이십일: '20' | |
이십일일: '21' | |
이십이일: '22' | |
이십삼일: '23' | |
이십사일: '24' | |
이십오일: '25' | |
이십육일: '26' | |
이십칠일: '27' | |
이십팔일: '28' | |
이십구일: '29' | |
삼십일: '30' | |
삼십일일: '31' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment