Class: CARPS::Sheet::TypeParser
- Inherits:
-
Object
- Object
- CARPS::Sheet::TypeParser
- Defined in:
- lib/carps/mod/sheet/type.rb
Overview
Parse the sheet types from strings
Class Method Summary collapse
Class Method Details
.parse(type_name) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/carps/mod/sheet/type.rb', line 136 def TypeParser.parse type_name type_name.downcase! optional_match = type_name.match /^\s*optional\s+((\S+\s+)*?\S+)\s*$/ optional = false if optional_match type_name = optional_match[1] optional = true end if type_name == "integer" return Int.new optional elsif type_name == "text" return Text.new optional elsif type_name == "boolean" return Bool.new optional elsif match = type_name.match(/^choice (.+)$/) choices = Set.new match[1].split return Choice.new optional, choices else raise StandardError, "Could not parse type name: " + type_name end end |