Class: IOSParser::IOS::Document
- Inherits:
-
Object
- Object
- IOSParser::IOS::Document
- Includes:
- Enumerable, Queryable
- Defined in:
- lib/ios_parser/ios/document.rb
Instance Attribute Summary collapse
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#source ⇒ Object
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(source) ⇒ Document
constructor
A new instance of Document.
- #to_hash ⇒ Object
- #to_json ⇒ Object
- #to_s(dedent: false) ⇒ Object
Methods included from Queryable
#_find, #_find_all, #find, #find_all, #match_expr
Constructor Details
#initialize(source) ⇒ Document
Returns a new instance of Document.
12 13 14 15 16 |
# File 'lib/ios_parser/ios/document.rb', line 12 def initialize(source) @commands = [] @parent = nil @source = source end |
Instance Attribute Details
#commands ⇒ Object
Returns the value of attribute commands.
10 11 12 |
# File 'lib/ios_parser/ios/document.rb', line 10 def commands @commands end |
#parent ⇒ Object
Returns the value of attribute parent.
10 11 12 |
# File 'lib/ios_parser/ios/document.rb', line 10 def parent @parent end |
#source ⇒ Object
Returns the value of attribute source.
10 11 12 |
# File 'lib/ios_parser/ios/document.rb', line 10 def source @source end |
Class Method Details
.from_hash(hash) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ios_parser/ios/document.rb', line 40 def from_hash(hash) hash[:parent] = parent [:commands, :source].each do |key| val = hash.delete(key.to_s) hash[key] = val unless hash.key?(key) end new(source).tap do |doc| doc.push(*(hash[:commands].map { |c| Command.from_hash(c) })) end end |
Instance Method Details
#each ⇒ Object
22 23 24 |
# File 'lib/ios_parser/ios/document.rb', line 22 def each commands.each { |command| command.each { |cmd| yield cmd } } end |
#to_hash ⇒ Object
31 32 33 |
# File 'lib/ios_parser/ios/document.rb', line 31 def to_hash { commands: commands.map(&:to_hash) } end |
#to_json ⇒ Object
35 36 37 |
# File 'lib/ios_parser/ios/document.rb', line 35 def to_json JSON.dump(to_hash) end |
#to_s(dedent: false) ⇒ Object
26 27 28 29 |
# File 'lib/ios_parser/ios/document.rb', line 26 def to_s(dedent: false) base = dedent ? indentation : 0 map { |cmd| "#{cmd.indentation(base: base)}#{cmd.line}\n" }.join end |