Created
July 21, 2015 01:25
-
-
Save sonsongithub/46f9bafdee6edfd178e8 to your computer and use it in GitHub Desktop.
Create Thing class enum from HTML?
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
| def main | |
| types = ["Comment", "Link", "Message", "More", "Subreddit", "Listing", "Multireddit", "MultiredditDescription", "Account"] | |
| part1 = "" | |
| part2 = "" | |
| part3 = "" | |
| types.each{|type| | |
| part1 = part1 + sprintf($temp1, type, type) | |
| part2 = part2 + sprintf($temp2, type.downcase, type, type, type.downcase) | |
| part3 = part3 + sprintf($temp3, type.downcase, type, type, type.downcase, type.downcase) | |
| } | |
| puts sprintf($temp4, part1, part2, part3) | |
| end | |
| $temp1 = " case %sType(%s)\n" | |
| $temp2 = <<"EOS" | |
| public init(_ %s:%s) { | |
| self = .%sType(%s) | |
| } | |
| EOS | |
| $temp3 = <<"EOS" | |
| public var %s:%s? { | |
| switch self { | |
| case .%sType(let %s): | |
| return %s | |
| default: | |
| return nil | |
| } | |
| } | |
| EOS | |
| $temp4 = <<"EOS" | |
| public enum Thing { | |
| %s | |
| %s | |
| %s} | |
| EOS | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment