Class: Pubid::Bsi::Parser
- Inherits:
-
Parslet::Parser
- Object
- Parslet::Parser
- Pubid::Bsi::Parser
- Defined in:
- lib/pubid/bsi/parser.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#stri(string) ⇒ Object
Case-insensitive string match (Parslet 2.0 has no built-in
stri).
Class Method Details
.parse(input) ⇒ Object
662 663 664 665 666 667 668 669 670 |
# File 'lib/pubid/bsi/parser.rb', line 662 def self.parse(input) # Normalize "BSI " to "BS " for consistency, but NOT for "BSI Flex" normalized = if input.start_with?("BSI Flex") input # Keep as is else input.gsub(/\bBSI\s+/, "BS ") end new.parse(normalized) end |
Instance Method Details
#stri(string) ⇒ Object
Case-insensitive string match (Parslet 2.0 has no built-in stri).
Each character becomes a two-case character class; other characters
(spaces, punctuation) match verbatim.
11 12 13 14 15 16 17 18 19 |
# File 'lib/pubid/bsi/parser.rb', line 11 def stri(string) string.each_char.map do |char| if char =~ /[a-z]/i match["#{char.upcase}#{char.downcase}"] else str(char) end end.reduce(:>>) end |