Class: XLIFFer::XLIFF::File

Inherits:
Object
  • Object
show all
Defined in:
lib/xliffer/xliff/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ File

Returns a new instance of File.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/xliffer/xliff/file.rb', line 9

def initialize(xml)
  unless XLIFF::xml_element?(xml) and file?(xml)
    raise ArgumentError, "can't create a File without a file subtree"
  end

  @xml = xml

  @original = @xml.attr("original")
  @source_language = @xml.attr("source-language")
  @target_language = @xml.attr("target-language")
  @strings = @xml.xpath('.//trans-unit').map{|tu| String.new(tu) }
end

Instance Attribute Details

#originalObject (readonly) Also known as: file_name

Returns the value of attribute original.



7
8
9
# File 'lib/xliffer/xliff/file.rb', line 7

def original
  @original
end

#source_languageObject

Returns the value of attribute source_language.



7
8
9
# File 'lib/xliffer/xliff/file.rb', line 7

def source_language
  @source_language
end

#stringsObject (readonly)

Returns the value of attribute strings.



7
8
9
# File 'lib/xliffer/xliff/file.rb', line 7

def strings
  @strings
end

#target_languageObject

Returns the value of attribute target_language.



7
8
9
# File 'lib/xliffer/xliff/file.rb', line 7

def target_language
  @target_language
end

Instance Method Details

#[](id) ⇒ Object



22
23
24
# File 'lib/xliffer/xliff/file.rb', line 22

def [](id)
  @strings.find { |s| s.id == id }
end

#[]=(id, target) ⇒ Object



26
27
28
# File 'lib/xliffer/xliff/file.rb', line 26

def []=(id, target)
  self[id].target = target
end