Class: Occi::Core::Parsers::Text::Location
- Inherits:
-
Object
- Object
- Occi::Core::Parsers::Text::Location
- Includes:
- Helpers::ErrorHandler, Yell::Loggable
- Defined in:
- lib/occi/core/parsers/text/location.rb
Overview
Static parsing class responsible for extracting URI-like locations from plain text. Class supports both ‘text/uri-list’ and ‘text/plain’ via ‘uri_list` and `plain` respectively.
Class Method Summary collapse
-
.plain(lines) ⇒ Array
Parses text/plain OCCI locations into ‘URI` instances suitable for futher processing.
-
.uri_list(lines) ⇒ Array
Parses text/uri-list lines into ‘URI` instances suitable for futher processing.
Methods included from Helpers::ErrorHandler
Class Method Details
.plain(lines) ⇒ Array
Parses text/plain OCCI locations into ‘URI` instances suitable for futher processing. Every location line is expected to begin with ’X-OCCI-Location’.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/occi/core/parsers/text/location.rb', line 19 def plain(lines) regexp = Regexp.new(Constants::REGEXP_LOCATION) locations = lines.map do |line| next if line.blank? logger.debug { "Parsing location from line #{line.inspect}" } matched = line.match(regexp) unless matched raise Occi::Core::Errors::ParsingError, "#{line.inspect} does not match 'X-OCCI-Location: URI'" end handle(Occi::Core::Errors::ParsingError) { URI.parse(matched[:location].strip) } end locations.compact end |
.uri_list(lines) ⇒ Array
Parses text/uri-list lines into ‘URI` instances suitable for futher processing. Lines starting with ’#‘ are ommited, as per tools.ietf.org/html/rfc2483#section-5
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/occi/core/parsers/text/location.rb', line 41 def uri_list(lines) uris = lines.map do |line| next if line.blank? || line.start_with?('#') logger.debug { "Parsing location from line #{line.inspect}" } handle(Occi::Core::Errors::ParsingError) { URI.parse(line.strip) } end uris.compact end |