Class: Gherkin::Formatter::Model::Hashable

Inherits:
Object
  • Object
show all
Defined in:
lib/gherkin/formatter/model.rb

Direct Known Subclasses

BasicStatement, Comment, PyString, Row, Tag

Instance Method Summary collapse

Instance Method Details

#to_hashObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/gherkin/formatter/model.rb', line 7

def to_hash
  instance_variables.inject({}) do |hash, ivar|
    value = instance_variable_get(ivar)
    value = value.to_hash if value.respond_to?(:to_hash)
    if Array === value
      value = value.map do |e|
        e.respond_to?(:to_hash) ? e.to_hash : e
      end
    end
    hash[ivar[1..-1]] = value unless [[], nil].index(value)
    hash
  end
end