Class: AndroidXml::XmlFile
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Attributes inherited from Tag
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(filename, &block) ⇒ XmlFile
constructor
A new instance of XmlFile.
- #method_missing(method_name, *args, &block) ⇒ Object
- #out ⇒ Object
- #write ⇒ Object
Methods inherited from Tag
#attrs, #generate_block, #to_ary, #to_s
Constructor Details
#initialize(filename, &block) ⇒ XmlFile
Returns a new instance of XmlFile.
7 8 9 10 11 |
# File 'lib/android-xml/file.rb', line 7 def initialize(filename, &block) @filename = filename super(nil, &block) AndroidXml.files << self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/android-xml/file.rb', line 13 def method_missing(method_name, *args, &block) raise "There can be only one (new: #{method_name}, old: #{@root})" if @root @root = super @root.is_root = true @root end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
5 6 7 |
# File 'lib/android-xml/file.rb', line 5 def filename @filename end |
Instance Method Details
#generate ⇒ Object
21 22 23 24 25 |
# File 'lib/android-xml/file.rb', line 21 def generate output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" output << "<!-- Do not edit this file. It was generated by AndroidXml -->\n" output << generate_block end |
#out ⇒ Object
27 28 29 30 31 |
# File 'lib/android-xml/file.rb', line 27 def out puts "---- filename: #{@filename} ----" super puts "---------------#{'-' * @filename.to_s.length}-----" end |
#write ⇒ Object
33 34 35 36 37 38 |
# File 'lib/android-xml/file.rb', line 33 def write File.open(self.filename, 'w') do |f| f.write(self.to_s) end puts "\033[32m✓\033[0m #{self.filename}" end |