Module: ZergXcode::Encoder
- Defined in:
- lib/zerg_xcode/file_format/encoder.rb
Class Method Summary collapse
- .encode(project) ⇒ Object
- .encode_array(array, indentation) ⇒ Object
- .encode_hash(hash, indentation) ⇒ Object
- .encode_indentation(indentation) ⇒ Object
- .encode_object(object, indentation) ⇒ Object
- .encode_value(value, indentation) ⇒ Object
Class Method Details
.encode(project) ⇒ Object
2 3 4 |
# File 'lib/zerg_xcode/file_format/encoder.rb', line 2 def self.encode(project) "// !$*UTF8*$!\n" + encode_hash(project, 0) + "\n" end |
.encode_array(array, indentation) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/zerg_xcode/file_format/encoder.rb', line 25 def self.encode_array(array, indentation) "(\n" + array.map { |value| encode_indentation(indentation + 1) + encode_object(value, indentation + 1) + ",\n" }.join + encode_indentation(indentation) + ")" end |
.encode_hash(hash, indentation) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/zerg_xcode/file_format/encoder.rb', line 6 def self.encode_hash(hash, indentation) "{\n" + hash.keys.sort.map { |key| encode_indentation(indentation + 1) + encode_value(key, indentation + 1) + " = " + encode_object(hash[key], indentation + 1) + ";\n" }.join + encode_indentation(indentation) + "}" end |
.encode_indentation(indentation) ⇒ Object
37 38 39 |
# File 'lib/zerg_xcode/file_format/encoder.rb', line 37 def self.encode_indentation(indentation) "\t" * indentation end |
.encode_object(object, indentation) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/zerg_xcode/file_format/encoder.rb', line 14 def self.encode_object(object, indentation) case object when Hash encode_hash object, indentation when Array encode_array object, indentation when String encode_value object, indentation end end |
.encode_value(value, indentation) ⇒ Object
32 33 34 35 |
# File 'lib/zerg_xcode/file_format/encoder.rb', line 32 def self.encode_value(value, indentation) # This escapes what needs to be escaped. value.to_s.inspect end |