Class: Srx::Data::LanguageRule::Rule

Inherits:
XmlWrapper
  • Object
show all
Defined in:
lib/srx/data.rb

Overview

SRX <rule> element

Constant Summary

Constants inherited from XmlWrapper

XmlWrapper::NS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Rule

Returns a new instance of Rule.



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/srx/data.rb', line 127

def initialize(xml)
  super(xml)

  # Eagerly load everything for this class because before_break and
  # after_break can be legitimately nil, so lazy loading gets ugly.

  @break = @xml['break'].then { |brk| brk.nil? || brk == 'yes' }

  @before_break = xpath(:beforebreak).first&.text.then do |pattern|
    IcuRegex.compile(pattern) if pattern
  end

  @after_break = xpath(:afterbreak).first&.text.then do |pattern|
    IcuRegex.compile(pattern) if pattern
  end
end

Instance Attribute Details

#after_breakRegexp? (readonly)

Returns:

  • (Regexp, nil)


125
126
127
# File 'lib/srx/data.rb', line 125

def after_break
  @after_break
end

#before_breakRegexp? (readonly)

Returns:

  • (Regexp, nil)


122
123
124
# File 'lib/srx/data.rb', line 122

def before_break
  @before_break
end

Instance Method Details

#break?Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/srx/data.rb', line 144

def break?
  @break
end

#inspectObject



148
149
150
# File 'lib/srx/data.rb', line 148

def inspect
  "Rule[break=#{break?},before=#{before_break},after=#{after_break}]"
end