class Srx::Data

SRX data

Public Class Methods

default() click to toggle source

Default SRX rules

@return [Data]

# File lib/srx/data.rb, line 28
def default
  from_file(path: File.expand_path('srx-20-sample.srx', __dir__))
end
from_file(path:) click to toggle source

@param path [String] @return [Data]

# File lib/srx/data.rb, line 34
def from_file(path:)
  File.open(path, &method(:from_io))
end
from_io(io) click to toggle source

@param io [IO] @return [Data]

# File lib/srx/data.rb, line 40
def from_io(io)
  new(Nokogiri::XML.parse(io))
end

Public Instance Methods

cascade?() click to toggle source
# File lib/srx/data.rb, line 49
def cascade?
  @cascade ||= header['cascade'] == 'yes'
end
include_end_formatting?() click to toggle source
# File lib/srx/data.rb, line 57
def include_end_formatting?
  @include_end_formatting ||= include_formatting?(:end)
end
include_isolated_formatting?() click to toggle source
# File lib/srx/data.rb, line 61
def include_isolated_formatting?
  @include_isolated_formatting ||= include_formatting?(:isolated)
end
include_start_formatting?() click to toggle source
# File lib/srx/data.rb, line 53
def include_start_formatting?
  @include_start_formatting ||= include_formatting?(:start)
end
language_rules() click to toggle source

@return [Array<LanguageRule>]

# File lib/srx/data.rb, line 66
def language_rules
  @language_rules ||=
    xpath(:srx, :body, :languagerules, :languagerule)
    .map { |langrule| LanguageRule.new(langrule) }
end
map_rules() click to toggle source

@return [Array<LanguageMap>]

# File lib/srx/data.rb, line 73
def map_rules
  @map_rules ||=
    xpath(:srx, :body, :maprules, :languagemap)
    .map { |maprule| LanguageMap.new(maprule) }
end
segment_subflows?() click to toggle source
# File lib/srx/data.rb, line 45
def segment_subflows?
  @segment_subflows ||= header['segmentsubflows'] == 'yes'
end

Private Instance Methods

format_handle(type) click to toggle source

@param type [Symbol]

# File lib/srx/data.rb, line 86
def format_handle(type)
  xpath(:srx, :header, "formathandle[@type='#{type}']").first
end
header() click to toggle source
# File lib/srx/data.rb, line 81
def header
  @header ||= xpath(:srx, :header).first
end
include_formatting?(type) click to toggle source

@param type [Symbol]

# File lib/srx/data.rb, line 91
def include_formatting?(type)
  elem = format_handle(type)

  return elem['include'] == 'yes' if elem

  # Defaults are
  #   <formathandle type="start" include="no"/>
  #   <formathandle type="end" include="yes"/>
  #   <formathandle type="isolated" include="no"/>
  case type
  when %i[start isolated] then false
  when :end then true
  else raise(ArgumentError, "Unknown formatting type: #{type}")
  end
end