Module: BEL::Quoting

Constant Summary collapse

NonWordMatcher =
Regexp.compile(/[^0-9a-zA-Z_]/)
KeywordMatcher =
Regexp.compile(/^(SET|DEFINE|a|g|p|r|m)$/)

Instance Method Summary collapse

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

Returns:

  • (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