Class: ONIX::ETextType

Inherits:
ROXML::XMLRef
  • Object
show all
Defined in:
lib/onix/etext_type.rb

Overview

::nodoc

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(accessor, args, &block) ⇒ ETextType

Returns a new instance of ETextType.



6
7
8
9
10
# File 'lib/onix/etext_type.rb', line 6

def initialize(accessor, args, &block)
  super(accessor, args, &block)
  @content = args.content?
  @cdata = args.cdata?
end

Instance Attribute Details

#cdataObject (readonly)

Returns the value of attribute cdata.



4
5
6
# File 'lib/onix/etext_type.rb', line 4

def cdata
  @cdata
end

#contentObject (readonly)

Returns the value of attribute content.



4
5
6
# File 'lib/onix/etext_type.rb', line 4

def content
  @content
end

Instance Method Details

#update_xml(xml, value) ⇒ Object

Updates the text in the given xml block to the value provided.



14
15
16
17
18
19
# File 'lib/onix/etext_type.rb', line 14

def update_xml(xml, value)
  value = value.to_s.gsub("&","&amp;").gsub("<","&lt;").gsub(">","&gt;")
  parent = wrap(xml)
  add(parent.child_add(LibXML::XML::Node.new_element(name)), value)
  xml
end

#value(xml) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/onix/etext_type.rb', line 21

def value(xml)
  if content
    value = xml.content
  else
    child = xml.search(name).first
    value = child.content if child
  end
  value = value.gsub("&amp;","&").gsub("&lt;","<").gsub("&gt;",">") if value
  block ? block.call(value) : value
end