Class: C11n::Importer::Android
- Inherits:
-
Object
- Object
- C11n::Importer::Android
- Defined in:
- lib/c11n/importer/android.rb
Instance Attribute Summary collapse
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #document ⇒ Object
- #file ⇒ Object
- #import ⇒ Object
-
#initialize(options = {}) ⇒ Android
constructor
A new instance of Android.
- #to_hash ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Android
Returns a new instance of Android.
9 10 11 12 13 14 |
# File 'lib/c11n/importer/android.rb', line 9 def initialize( = {}) @path = [:path] @locale = [:locale] @types = {} @categories = {} end |
Instance Attribute Details
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
7 8 9 |
# File 'lib/c11n/importer/android.rb', line 7 def categories @categories end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
7 8 9 |
# File 'lib/c11n/importer/android.rb', line 7 def types @types end |
Instance Method Details
#document ⇒ Object
20 21 22 |
# File 'lib/c11n/importer/android.rb', line 20 def document Nokogiri::XML(file) end |
#file ⇒ Object
16 17 18 |
# File 'lib/c11n/importer/android.rb', line 16 def file File.open(@path, 'r') end |
#import ⇒ Object
24 25 26 |
# File 'lib/c11n/importer/android.rb', line 24 def import { @locale.to_sym => to_hash } end |
#to_hash ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/c11n/importer/android.rb', line 28 def to_hash document.at_xpath('resources').elements.inject({}) do |result, element| if element.name == 'string' @types[element['name']] = C11n::Types::CDATA if element.children.any? { |child| child.cdata? } result.merge(element['name'] => element.text.strip) elsif element.name == 'string-array' @types[element['name']] = C11n::Types::ARRAY result.merge(element['name'] => element.elements.map(&:text)) end end end |