Module: BEL::Quoting
- Included in:
- Completion::MatchNamespaceValueRule, Extension::Format::EvidenceYielder, Extension::Format::RDFReader::EvidenceYielder, Language::Annotation, Language::DocumentProperty, Language::StatementGroup, Model::Parameter
- Defined in:
- lib/bel/quoting.rb
Constant Summary collapse
- NonWordMatcher =
Regexp.compile(/[^0-9a-zA-Z_]/)
- KeywordMatcher =
Regexp.compile(/^(SET|DEFINE|a|g|p|r|m)$/)
Instance Method Summary collapse
- #always_quote(identifier) ⇒ Object
- #ensure_quotes(identifier) ⇒ Object
- #quotes_required?(identifier) ⇒ Boolean
- #remove_quotes(identifier) ⇒ Object
Instance Method Details
#always_quote(identifier) ⇒ Object
22 23 24 25 26 |
# File 'lib/bel/quoting.rb', line 22 def always_quote identifier return "" unless identifier identifier.to_s.gsub! '"', '\"' %Q("#{identifier}") end |
#ensure_quotes(identifier) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/bel/quoting.rb', line 7 def ensure_quotes identifier return "" unless identifier identifier.to_s.gsub! '"', '\"' if quotes_required? identifier %Q{"#{identifier}"} else identifier end end |
#quotes_required?(identifier) ⇒ Boolean
28 29 30 |
# File 'lib/bel/quoting.rb', line 28 def quotes_required? identifier [NonWordMatcher, KeywordMatcher].any? { |m| m.match identifier } end |
#remove_quotes(identifier) ⇒ Object
17 18 19 20 |
# File 'lib/bel/quoting.rb', line 17 def remove_quotes identifier identifier.gsub!(/\A"|"\Z/, '') identifier end |