Module: DocuBot::MetaSection::Castable
- Defined in:
- lib/docubot/metasection.rb
Instance Method Summary collapse
Instance Method Details
#as_boolean ⇒ Object
4 5 6 |
# File 'lib/docubot/metasection.rb', line 4 def as_boolean self == 'true' end |
#as_list ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/docubot/metasection.rb', line 7 def as_list return [] if self.nil? # Replace commas inside quoted strings with unlikely-to-be-used Unicode # FIXME: This doesnt work for the sadistic case of "hello """, "world" csv = self.gsub( /("(?:[^",]|"")+),/, '\\1⥸' ) csv.split(/\s*,\s*/).map do |str| # Put real commas back, unquote, undouble internal quotes str[/^".*"$/] ? str[1..-2].gsub('⥸',',').gsub('""','"') : str end end |