class Xliffle::String
Attributes
id[R]
notes[R]
source[R]
target[R]
Public Class Methods
new(id, source_string, target_string, options = {})
click to toggle source
# File lib/xliffle/string.rb, line 7 def initialize(id, source_string, target_string, options = {}) @id = id @source_string = source_string @target_string = target_string @options = options @notes = [] end
Public Instance Methods
note(note, priority = 2)
click to toggle source
# File lib/xliffle/string.rb, line 15 def note(note, priority = 2) note = Xliffle::Note.new(note, priority: priority) @notes << note note end
to_xliff(xliff)
click to toggle source
# File lib/xliffle/string.rb, line 21 def to_xliff(xliff) xliff.tag!('trans-unit', attributes) do |tag| add_source_segment(tag) add_target_segment(tag) @notes.each do |note| note.to_xliff(tag) end end end
Private Instance Methods
add_source_segment(tag)
click to toggle source
# File lib/xliffle/string.rb, line 41 def add_source_segment(tag) return tag.source unless @source_string tag.source do |xml| segment(xml, @source_string) end end
add_target_segment(tag)
click to toggle source
# File lib/xliffle/string.rb, line 49 def add_target_segment(tag) return tag.target unless @target_string tag.target do |xml| segment(xml, @target_string) end end
attributes()
click to toggle source
# File lib/xliffle/string.rb, line 34 def attributes attributes = { id: @id } attributes[:resname] = @options[:resource_name] if @options[:resource_name] attributes end
segment(tag, value)
click to toggle source
# File lib/xliffle/string.rb, line 57 def segment(tag, value) if @options[:use_cdata] && value tag.cdata!(value) elsif @options[:no_escaping] && value tag << value else tag.text!(value) end end