Sha256: e5cfd77930a09b45e0337bab347e05a2d13fbf3213299c8a317fa9aed7cd1964
Contents?: true
Size: 1.25 KB
Versions: 9
Compression:
Stored size: 1.25 KB
Contents
require 'json' require_relative 'queryable' require_relative 'command' module IOSParser class IOS class Document include Enumerable include Queryable attr_accessor :commands, :parent, :source def initialize(source) @commands = [] @parent = nil @source = source end [:[], :push].each do |method| define_method(method) { |*args| commands.send(method, *args) } end def each commands.each { |command| command.each { |cmd| yield cmd } } end def to_s(dedent: false) base = dedent ? indentation : 0 map { |cmd| "#{cmd.indentation(base: base)}#{cmd.line}\n" }.join end def to_hash { commands: commands.map(&:to_hash) } end def to_json JSON.dump(to_hash) end class << self 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 end # class << self end # class Document end # class IOS end # class IOSParser
Version data entries
9 entries across 9 versions & 1 rubygems