Class: Moxml::XmlUtils::Encoder
- Inherits:
-
Object
- Object
- Moxml::XmlUtils::Encoder
- Defined in:
- lib/moxml/xml_utils/encoder.rb
Constant Summary collapse
- MAPPINGS =
{ none: {}, basic: { "<" => "<", ">" => ">", "&" => "&", }, quotes: { "'" => "'", '"' => """, }, full: { "<" => "<", ">" => ">", "'" => "'", '"' => """, "&" => "&", }, }.freeze
- MODES =
MAPPINGS.keys.freeze
Instance Attribute Summary collapse
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(text, mode = nil) ⇒ Encoder
constructor
A new instance of Encoder.
Constructor Details
#initialize(text, mode = nil) ⇒ Encoder
Returns a new instance of Encoder.
29 30 31 32 |
# File 'lib/moxml/xml_utils/encoder.rb', line 29 def initialize(text, mode = nil) @text = text @mode = valid_mode(mode) end |
Instance Attribute Details
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
6 7 8 |
# File 'lib/moxml/xml_utils/encoder.rb', line 6 def mode @mode end |
Instance Method Details
#call ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/moxml/xml_utils/encoder.rb', line 34 def call return @text if mode == :none @text.to_s.gsub(/[#{mapping.keys.join}]/) do |match| mapping[match] end end |