Sha256: 78a01c6daa8852ba3dfe979518b84bfda349ea8a2b691477d0722909cb71380c
Contents?: true
Size: 881 Bytes
Versions: 4
Compression:
Stored size: 881 Bytes
Contents
require 'hanami/utils/hash' module RSpec module Hanami class FormParser def call(html) meta_list = select_inputs(html).map! { |input| input_data_hash(input) } meta_list.map! { |hash| ::Hanami::Utils::Hash.new(hash).symbolize! } end private def select_inputs(html) html.scan(/<input.+>|<textarea[^<]+>/) end def input_data_hash(input) # trim all '<' and '>' chars. After that I add data # attr 'node' for first element (html tag name). And # in the end I split string on key-value pairs, trim '"' # and split key-value to key and value array. Hash[ input .tr('<', '') .tr('>', '') .prepend('node=') .split(' ') .map! { |key_value| key_value.tr('"', '').split('=') } ] end end end end
Version data entries
4 entries across 4 versions & 1 rubygems