Module: Ifdef::Truth

Extended by:
Truth
Included in:
Truth
Defined in:
lib/ifdef/truth.rb

Instance Method Summary collapse

Instance Method Details

#load_json(path) ⇒ Object

Loads and parseds a truth-hash from a JSON file.

path - The path of the JSON file.

Returns a Hash.



8
9
10
# File 'lib/ifdef/truth.rb', line 8

def load_json(path)
  parse_hash(JSON.parse(File.read(path)))
end

#parse_hash(hash) ⇒ Object

Convert a Hash like:

{ "true" => ["statement1", "statement2"], "false" => "statement3"}

to a Hash like:

{
  s(:send, nil, :statement1) => :true,
  s(:send, nil, :statement2) => :true,
  s(:send, nil, :statement3) => :false
}

hash - The Hash to convert.

Returns a new Hash.



27
28
29
30
31
32
33
# File 'lib/ifdef/truth.rb', line 27

def parse_hash(hash)
  hash.each_with_object({}) do |(key, values), new_hash|
    Array(values).each do |value|
      new_hash[Ifdef.parse(value)] = key.to_sym
    end
  end
end