Created
May 2, 2019 16:56
-
-
Save matheussilvasantos/92e92dfb842c8668426f15d67932b0ba to your computer and use it in GitHub Desktop.
Campo harmônico
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
@acordes ||= Hash.new {|h,k| h[k] = [] } | |
def lambda_handler(event:, context:) | |
@acordes ||= Hash.new {|h,k| h[k] = [] } | |
params = JSON.parse(event["body"]) | |
puts "[LOGGER] #{params}" | |
session = params["session"] | |
acorde = params["queryResult"]["parameters"]["acorde"] | |
@acordes[session].push(acorde) | |
puts "[LOGGER] #{search_acorde_in_harmonic_field(@acordes[session])}" | |
{ | |
headers: { | |
"Access-Control-Allow-Origin": "*" | |
}, | |
statusCode: 200, | |
body: JSON.generate({ | |
fulfillmentText: search_acorde_in_harmonic_field(@acordes[session]).join(" e ") | |
}) | |
} | |
end | |
def search_acorde_in_harmonic_field(acordes) | |
HARMONIC_FIELD.map do |harmonic_field| | |
puts "[LOGGER] #{(harmonic_field[:acordes] & acordes)}" | |
harmonic_field[:name] if (acordes - harmonic_field[:acordes]).empty? | |
end.compact | |
end | |
HARMONIC_FIELD = [ | |
{ | |
name: "Campo harmônico maior - Dó maior", | |
acordes: ["C7M", "Dm7", "Em7", "F7M", "G7", "Am7", "Bm7(b5)"] | |
}, | |
{ | |
name: "Campo harmônico maior - Ré maior", | |
acordes: ["D7M", "Em7", "F#m7"] | |
}, | |
{ | |
name: "Campo harmônico maior - Mi maior", | |
acordes: ["E7M"] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment