Sha256: a7a8dc2418265f68ecc3e247fa92f77adc24a465e11365638280f40216d1a622

Contents?: true

Size: 998 Bytes

Versions: 20

Compression:

Stored size: 998 Bytes

Contents

class Parser
  attr_accessor :output

  def initialize(field_name, qualifier_value, hash)
    @field_name = field_name
    @qualifier_value = qualifier_value
    @hash = hash
  end

  def parse
    if @qualifier_value.nil?
      recurse @hash
    else
      qualified_recurse @hash
    end
  end

  def recurse(object)
    if object.is_a? Hash
      if object.has_key? @field_name
        @output = object[@field_name]
      else
        object.each_pair do |_key, value|
          recurse value
        end
      end
    elsif object.is_a? Array
      object.each do |element|
        recurse element
      end
    end
  end

  def qualified_recurse(object)
    if object.is_a? Hash
      if object.has_value? @qualifier_value
        @output = object[@field_name]
      else
        object.each_pair do |_key, value|
          qualified_recurse value
        end
      end
    elsif object.is_a? Array
      object.each do |element|
        qualified_recurse element
      end
    end
  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
apidragon-1.8.0 lib/apidragon/parser.rb
apidragon-1.7.1 lib/apidragon/parser.rb
apidragon-1.7.0 lib/apidragon/parser.rb
apidragon-1.6.3 lib/apidragon/parser.rb
apidragon-1.6.2 lib/apidragon/parser.rb
apidragon-1.6.1 lib/apidragon/parser.rb
apidragon-1.6.0 lib/apidragon/parser.rb
apidragon-1.5.4 lib/apidragon/parser.rb
apidragon-1.5.3 lib/apidragon/parser.rb
apidragon-1.5.2 lib/apidragon/parser.rb
apidragon-1.5.1 lib/apidragon/parser.rb
apidragon-1.5.0 lib/apidragon/parser.rb
apidragon-1.4.6 lib/apidragon/parser.rb
apidragon-1.4.5 lib/apidragon/parser.rb
apidragon-1.4.4 lib/apidragon/parser.rb
apidragon-1.4.3 lib/apidragon/parser.rb
apidragon-1.4.1 lib/apidragon/parser.rb
apidragon-1.4.0 lib/apidragon/parser.rb
apidragon-1.3.0 lib/apidragon/parser.rb
apidragon-1.2.1 lib/apidragon/parser.rb